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)); controller.Should().BeSameAs(secondController); }
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(); }