using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Sarand.BusinessMgr.Net.Core.Web.Middleware { //======================================================================= /// /// Maps a browser request to a data object. Default class provides a base implementation of a model binder. /// Overridden to trim whitespace from input values. /// public class SbmModelBinderProvider : IModelBinderProvider { //------------------------------------------------------------------- // Data members. //------------------------------------------------------------------- // Construction. public SbmModelBinderProvider() { } //------------------------------------------------------------------- public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) throw new ArgumentNullException(nameof(context)); if (context.Metadata.IsComplexType && !context.Metadata.IsCollectionType) { var propertyBinders = context.Metadata.Properties.ToDictionary(property => property, context.CreateBinder); ILoggerFactory loggerFactory = (ILoggerFactory)context.Services.GetService(typeof(ILoggerFactory)); return new SbmModelBinder(propertyBinders, loggerFactory); } // Default - return null so that default binding provider is used. return null; } } //======================================================================= }