예제 #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));
        }
예제 #2
0
        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()));
        }
예제 #3
0
        public static void RegisterPlumbing(HttpContext context)
        {
            // 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(context.Server.MapPath("~/"), "Tenants"));

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

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

            foreach (var tenant in tenantSelector.Tenants)
            {
                var types = new Type[2];
                types[0] = tenant.GetType();
                types[1] = typeof(MvcApplication);
                tenant.DependencyContainer = RazorMultiTenancy.AssemblySettings.FormContainer(types, config => config.For <ITenant>().Singleton().Use(tenant));
            }

            var containerSelector = new TenantContainerResolver(tenantSelector);

            // clear view engines, we don't want anything other than tenant view engine
            ViewEngines.Engines.Clear();

            // set view engine
            var engine = new TenantViewEngine(tenantSelector);

            foreach (ITenant tenant in tenantSelector.Tenants)
            {
                System.Web.WebPages.VirtualPathFactoryManager.RegisterVirtualPathFactory((System.Web.WebPages.IVirtualPathFactory)tenant.ViewEngine);
            }

            ViewEngines.Engines.Add(engine);
            ViewEngines.Engines.Add(new RazorViewEngine());

            // set controller factory
            ControllerBuilder.Current.SetControllerFactory(new ContainerControllerFactory(containerSelector));
        }