public void ConfigureMvc() { if (_hasRunInitialization) { // // * **All** Roadkill MVC controllers are new'd up by MvcDependencyResolver so dependencies are injected into them // * Some view models are new'd up by custom MvcModelBinders so dependencies are injected into them // * MVC Attributes are injected using setter injection // * All views use RoadkillViewPage which is setter injected. // * All layout views use RoadkillLayoutPage which uses bastard injection (as master pages are part of ASP.NET and not MVC) // MvcDependencyResolver mvcResolver = new MvcDependencyResolver(); GlobalConfiguration.Configuration.DependencyResolver = mvcResolver; // web api GlobalConfiguration.Configuration.Services.Add(typeof(System.Web.Http.Filters.IFilterProvider), new MvcAttributeProvider(GlobalConfiguration.Configuration.Services.GetFilterProviders())); // web api DependencyResolver.SetResolver(mvcResolver); // views and controllers FilterProviders.Providers.Add(new MvcAttributeProvider()); // attributes ModelBinders.Binders.Add(typeof(UserViewModel), new UserViewModelModelBinder()); // models needing DI ModelBinders.Binders.Add(typeof(SettingsViewModel), new SettingsViewModelBinder()); // Attachments path AttachmentRouteHandler.RegisterRoute(_applicationSettings, RouteTable.Routes); } else { throw new IoCException("Please call Run() to perform IoC initialization before performing MVC setup.", null); } }
/// <summary> /// 构造器 /// </summary> public RequestLifetimeModule() { //初始化容器 this.InitContainer(); this._dependencyResolver = new MvcDependencyResolver(); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); // MvcDependencyResolver.ForRepositoriesUseSharpRepository("repository.json", "sharpRepository", "efConnectionString"); // holds connection string on repository.json MvcDependencyResolver.ForRepositoriesUseSharpRepository("repository.json", "sharpRepository", lifecycle: Lifecycles.Unique); // no connection string on repository.json }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); MvcDependencyResolver.ForRepositoriesUseSharpRepository("repository.json", "sharpRepository", null, Lifecycles.Get <SingletonLifecycle>()); }
public void Execute() { if (HostingEnvironment.IsHosted) { MvcDependencyResolver.Register(); AreaRegistration.RegisterAllAreas(); ConfigureBinders(); Config config = ConfigManager.GetConfig(true); ConfigureFilters(config); ConfigureViewEngine(); ConfigureRoutes(); } }