public void Tilgangskontroll() { var container = new WindsorContainer(); container.Install(new DependencyConventions()); var controllerFactory = new WindsorMvcControllerFactory(container); var apiControllerFactory = new WindsorControllerActivator(container); //var t1 = ServiceLocator.Current.Resolve<TilgangsKontroll>(); //var t2 = controllerFactory.CreateController() }
/// <summary>Setup our IoC container and register a custom controllerFactory to use it /// </summary> private void SetupIoC(HttpConfiguration config) { // setup a windsor container using any installers declared in this assembly container = new WeeWorldWindsorContainer(); // replace default Controller Factory with dedicated WeeWorld one (for MVC Controllers) //var controllerFactory = new WindsorControllerFactory(container.Kernel); //ControllerBuilder.Current.SetControllerFactory(controllerFactory); // replace default Controller Activator with dedicated WeeWorld one (for API controllers) var controllerActivator = new WindsorControllerActivator(container); config.Services.Replace(typeof(IHttpControllerActivator), controllerActivator); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); // Setup DocumentDB schema. DocumentDbConfig.Initialize(); // Setup IoC container for ApiControllers. container = new WindsorContainer().Install(FromAssembly.This()); WindsorControllerActivator activator = new WindsorControllerActivator(container.Kernel); GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerActivator), activator); }
public static void Config(IWindsorContainer container, HttpConfiguration config) { if (container == null) { throw new ArgumentNullException("container"); } container.Install(new CastleConfig()); IHttpControllerActivator controllerFactory = new WindsorControllerActivator(container); if (config != null) { config.Services.Replace(typeof(IHttpControllerActivator), controllerFactory); var dependencyResolver = new WindsorDependencyResolver(container); config.DependencyResolver = dependencyResolver; } }
protected void Application_Start() { Cfg.AppSettings.Init <IConfig>(); System.Data.Entity.Database.SetInitializer(new CustomDatabaseInitializer()); Container = new WindsorContainer().Install(FromAssembly.This()); // custom controllerfactory ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(Container.Kernel)); var controllerActivator = new WindsorControllerActivator(Container.Kernel); // Replace default API controller activator with custom one GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerActivator), controllerActivator); AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(x => WebApiConfig.Register(x, Container)); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); }