/// <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 void Setup() { _routes = new List <ActionDescriptor>(); _routes.Add( new ActionDescriptor( null, null )); _routes.Add( new ActionDescriptor( null, new RouteInfo(updateTypes: UpdateTypeExtensions.All) )); _routes.Add( new ActionDescriptor( null, new RouteInfo(template: " ", updateTypes: UpdateTypeExtensions.All) )); _routes.Add( new ActionDescriptor( async(ctx) => { SetHandlerIdentifier(ctx, "M_LowPriority"); }, new RouteInfo(template: "t2", order: 2, name: "LowPriority", updateTypes: UpdateTypeExtensions.All) )); _routes.Add( new ActionDescriptor( async(ctx) => { SetHandlerIdentifier(ctx, "M_HightPriority"); }, new RouteInfo(template: "t2", order: -1, name: "HightPriority", updateTypes: UpdateTypeExtensions.All) )); _routes.Add( new ActionDescriptor( async(ctx) => { SetHandlerIdentifier(ctx, "M_NormalPriority"); }, new RouteInfo(template: "t2", order: 1, name: "NormalPriority", updateTypes: UpdateTypeExtensions.All) )); _routes.Add( new ActionDescriptor( async(ctx) => { SetHandlerIdentifier(ctx, "Message"); }, new RouteInfo(template: "t3", order: 1, updateTypes: new UpdateType[] { UpdateType.Message }) )); _routes.Add( new ActionDescriptor( async(ctx) => { SetHandlerIdentifier(ctx, "ChannelPost"); }, new RouteInfo(template: "t3", order: 1, updateTypes: new UpdateType[] { UpdateType.ChannelPost }) )); _sb = new GlobalSearchBag(_routes, true); }
internal static void SetGlobalSearchBag(this UpdateContext ctx, IGlobalSearchBag globalSearchBag) { ctx.Properties["_GlobalSearchBag"] = globalSearchBag; }