Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.AspNet.Mvc.ModelBinding;
- using System;
- using System.Threading.Tasks;
- namespace TestDependencyInjection.Lib
- {
- public class SomeProviderModelBinder : IModelBinder
- {
- public Task<ModelBindingResult> BindModelAsync(ModelBindingContext bindingContext)
- {
- try
- {
- object someProvider = bindingContext.OperationBindingContext.HttpContext.ApplicationServices.GetService(bindingContext.ModelType);
- if (someProvider != null)
- {
- return Task.FromResult(new ModelBindingResult(someProvider, bindingContext.ModelName, true));
- }
- }
- catch (Exception ex)
- {
- //LogException(ex);
- }
- return Task.FromResult<ModelBindingResult>(null);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment