public static void RegisterDependencies() { var builder = new ContainerBuilder(); var controllerAssembly = Assembly.GetExecutingAssembly(); var controllerRegistrationModule = new ControllerRegistrationModule(controllerAssembly); builder.RegisterModule(controllerRegistrationModule); builder.Register<IFoo, Foo>(); builder.Register<IFormsAuthentication>(c => new FormsAuthenticationService()); builder.Register<IMembershipService>(c => new AccountMembershipService()); builder.Register<IWelcomeRepository, WelcomeRepository>(); _container = builder.Build(); }
protected void Application_Start() { ContainerBuilder builder = new ContainerBuilder(); builder.Register<IFoo, Foo>(); var controllerRegistrationModule = new ControllerRegistrationModule(Assembly.GetExecutingAssembly()); controllerRegistrationModule.Register(builder); var container = builder.Build(); DependencyResolver.SetResolver(new LightCoreDependencyResolver(container)); AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); }
public void Registered_controller_instances_are_reused_on_httpcontextstrategy() { var builder = new ContainerBuilder(); var registrationModule = new ControllerRegistrationModule(typeof(FooController).Assembly); var currentItems = new Dictionary<string, object>(); var currentContext = new Mock<HttpContextBase>(); currentContext .Setup(c => c.Items) .Returns(currentItems); builder.DefaultControlledBy(() => new HttpRequestLifecycle { CurrentContext = currentContext.Object }); builder.RegisterModule(registrationModule); var container = builder.Build(); var controllerFactory = new ControllerFactory(container); var controller = controllerFactory.CreateControllerInternal(this.CreateRequestContext(), typeof(FooController)); var secondController = controllerFactory.CreateControllerInternal(this.CreateRequestContext(), typeof(FooController)); Assert.That(controller, Is.SameAs(secondController)); }