protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); // Register injectable things DI.RegisterTransient <IRepository <Picture>, DatabaseRepository <Picture> >(); DI.RegisterTransient <IRepository <Tag>, DatabaseRepository <Tag> >(); // Add DI to our controllers ControllerBuilder.Current.SetControllerFactory(typeof(InjectingControllerFactory)); // MVC controllers only, doing this for Web API sucks }
protected void Application_EndRequest() { DI.UnregisterScoped(HttpContext.Current.Items["Context"]); }
protected void Application_BeginRequest() { HttpContext.Current.Items["Context"] = Guid.NewGuid(); DI.RegisterScoped(HttpContext.Current.Items["Context"], new PictureTaggerContext()); }