Exemplo n.º 1
0
        protected void Application_Start()
        {
            // I'm not using areas... no need to register.
            // AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);

            // create a container just to pull in tenants
            var topContainer = new Container();
            topContainer.Configure(config =>
            {
                config.Scan(scanner =>
                {
                    // scan the tenants folder
                    // (For some reason just passing "Tenants" doesn't seem to work, which it should according to the docs)
                    scanner.AssembliesFromPath(Path.Combine(Server.MapPath("~/"), "Tenants"));

                    // pull in all the tenant types
                    scanner.AddAllTypesOf<IApplicationTenant>();
                });
            });

            // create selectors
            var tenantSelector = new DefaultTenantSelector(topContainer.GetAllInstances<IApplicationTenant>());
            var containerSelector = new TenantContainerResolver(tenantSelector);

            // clear view engines, we don't want anything other than spark
            ViewEngines.Engines.Clear();
            // set view engine
            ViewEngines.Engines.Add(new TenantViewEngine(tenantSelector));

            // set controller factory
            ControllerBuilder.Current.SetControllerFactory(new ContainerControllerFactory(containerSelector));
        }
 public void TenantContainerResolver_Resolve_ReturnsContainerFromSelectedTenant()
 {
     var container = new Container();
     var tenant = new Mock<IApplicationTenant>();
     tenant.Setup(x=>x.DependencyContainer).Returns(container);
     var tenantSelector = new Mock<ITenantSelector>();
     tenantSelector.Setup(x => x.Select(It.IsAny<RequestContext>())).Returns(tenant.Object);
     var resolver = new TenantContainerResolver(tenantSelector.Object);
     Assert.Same(container, resolver.Resolve(new RequestContext()));
 }