/// <summary> /// All other services will be resolved from ServiceProvider. /// </summary> public MvcMiddleware( MvcOptions mvcOptions, IUseMvcBuilder useMvcBuilder ) { useMvcBuilder.Routers = useMvcBuilder.Routers ?? new List <IRouter>(); useMvcBuilder.ModelBinders = useMvcBuilder.ModelBinders ?? new List <IModelBinder>(); _mvcOptions = (MvcOptions)mvcOptions.Clone(); var serv = useMvcBuilder.ServiceProvider; _mainRouter = new MainRouter(useMvcBuilder.Routers); _contextPreparer = serv.GetRequiredService <IContextPreparer>(); //Controllers. var controllers = useMvcBuilder.Controllers ?? new List <Type>(); var startupRoutes = useMvcBuilder.GetRoutes(); _globalSearchBag = CreateGlobalSearchBag(serv, startupRoutes, controllers); var mainModelBinder = new MainModelBinder(useMvcBuilder.ModelBinders); //Init services bus. _servicesBus = serv.GetRequiredService <ServicesBus>(); var outerMiddlewaresInformer = new OuterMiddlewaresInformer(_mainRouter); var mvcFeatures = new MvcFeatures(); _servicesBus.Init( _mainRouter, outerMiddlewaresInformer, mvcFeatures, mainModelBinder ); }
public static void InitUseMvcBuilder(IUseMvcBuilder builder) { //Add Model binders. builder.ModelBinders = new List <IModelBinder> { new SpacingModelBinder() }; }
public static void MapRouteAction( this IUseMvcBuilder @this, RouteActionDelegate routeAction, string template = null, int order = 0, string name = null, UpdateType[] updateTypes = null ) { var routeInfo = new RouteInfo(template, order, name, updateTypes); @this.MapRouteAction(routeAction, routeInfo); }
public static void RemoveControllersByNamespace( this IUseMvcBuilder @this, string namespaceToRemove ) { if (namespaceToRemove == null) { throw new ArgumentNullException(nameof(namespaceToRemove)); } @this.Controllers = @this.Controllers ?? new List <Type>(); var filteredControllers = new List <Type>(); foreach (var type in @this.Controllers) { if (!type.Namespace.StartsWith(namespaceToRemove)) { filteredControllers.Add(type); } } @this.Controllers = filteredControllers; }