/// <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 ); }
async Task InvokeActionByName(ActionContext prevActionContext, int invokesCount) { var max = _mvcOptions.StartAnotherActionMaxStackLevel; if (invokesCount > max) { throw new TelegramAspException($"StartAnotherAction invoked recursive more than {max} times. " + $"You can change max value in MvcOptions."); } var startAnotherActionData = MvcFeatures.GetData(prevActionContext); if (startAnotherActionData == null) { return; } var actName = startAnotherActionData.ActionName; var ctx = prevActionContext.UpdateContext; var actDesc = _globalSearchBag.FindByName(actName); if (actDesc == null) { throw new TelegramAspException($"Can't find action with name '{actName}'."); } var actionContext = _contextPreparer.CreateContext(ctx, actDesc); await actDesc.Handler.Invoke(actionContext); //Check again. await InvokeActionByName(actionContext, invokesCount + 1); }