private IContainer CreateHostContainer() { var hostContainer = CoeveryStarter.CreateHostContainer(ContainerRegistrations); var host = hostContainer.Resolve <ICoeveryHost>(); host.Initialize(); return(hostContainer); }
public void MostRecentlyRegisteredServiceReturnsFromSingularResolve() { var container = CoeveryStarter.CreateHostContainer(builder => { builder.RegisterType <Component1>().As <IServiceA>(); builder.RegisterType <Component2>().As <IServiceA>(); }); var service = container.Resolve <IServiceA>(); Assert.That(service, Is.Not.Null); Assert.That(service, Is.TypeOf <Component2>()); }
private static ICoeveryHost HostInitialization(HttpApplication application) { var host = CoeveryStarter.CreateHost(MvcSingletons); host.Initialize(); // initialize shells to speed up the first dynamic query host.BeginRequest(); host.EndRequest(); return(host); }
public void ContainerResolvesServicesInSameOrderTheyAreRegistered() { var container = CoeveryStarter.CreateHostContainer(builder => { builder.RegisterType <Component1>().As <IServiceA>(); builder.RegisterType <Component2>().As <IServiceA>(); }); var services = container.Resolve <IEnumerable <IServiceA> >(); Assert.That(services.Count(), Is.EqualTo(2)); Assert.That(services.First(), Is.TypeOf <Component1>()); Assert.That(services.Last(), Is.TypeOf <Component2>()); }
public void Init() { var clock = new StubClock(); var appDataFolder = new StubAppDataFolder(clock); _controllerBuilder = new ControllerBuilder(); _routeCollection = new RouteCollection(); _modelBinderDictionary = new ModelBinderDictionary(); _viewEngineCollection = new ViewEngineCollection { new WebFormViewEngine() }; _container = CoeveryStarter.CreateHostContainer( builder => { builder.RegisterInstance(new StubShellSettingsLoader()).As <IShellSettingsManager>(); builder.RegisterType <RoutePublisher>().As <IRoutePublisher>(); builder.RegisterType <ModelBinderPublisher>().As <IModelBinderPublisher>(); builder.RegisterType <ShellContextFactory>().As <IShellContextFactory>(); builder.RegisterType <StubExtensionManager>().As <IExtensionManager>(); builder.RegisterType <StubVirtualPathMonitor>().As <IVirtualPathMonitor>(); builder.RegisterInstance(appDataFolder).As <IAppDataFolder>(); builder.RegisterInstance(_controllerBuilder); builder.RegisterInstance(_routeCollection); builder.RegisterInstance(_modelBinderDictionary); builder.RegisterInstance(_viewEngineCollection); builder.RegisterAutoMocking() .Ignore <IExtensionFolders>() .Ignore <IRouteProvider>() .Ignore <IHttpRouteProvider>() .Ignore <IModelBinderProvider>(); }); _lifetime = _container.BeginLifetimeScope(); _container.Mock <IContainerProvider>() .SetupGet(cp => cp.ApplicationContainer).Returns(_container); _container.Mock <IContainerProvider>() .SetupGet(cp => cp.RequestLifetime).Returns(_lifetime); _container.Mock <IContainerProvider>() .Setup(cp => cp.EndRequestLifetime()).Callback(() => _lifetime.Dispose()); _container.Mock <IShellDescriptorManager>() .Setup(cp => cp.GetShellDescriptor()).Returns(default(ShellDescriptor)); _container.Mock <ICoeveryShellEvents>() .Setup(e => e.Activated()); _container.Mock <ICoeveryShellEvents>() .Setup(e => e.Terminating()).Callback(() => new object()); }
public void DefaultCoeveryHostInstanceReturnedByCreateHost() { var host = CoeveryStarter.CreateHost(b => b.RegisterInstance(new ControllerBuilder())); Assert.That(host, Is.TypeOf <DefaultCoeveryHost>()); }
public void Init() { _hostContainer = CoeveryStarter.CreateHostContainer(builder => { builder.RegisterType <Alpha>().InstancePerDependency(); }); }