Example #1
0
        public static MultitenancyOptionsBuilder <TTenant> ConfigureTenantContainers <TTenant>(
            this MultitenancyOptionsBuilder <TTenant> optionsBuilder,
            Action <ContainerBuilderOptions <TTenant> > configure)
            where TTenant : class
        {
            var containerOptionsBuilder = new ContainerBuilderOptions <TTenant>(optionsBuilder);

            configure?.Invoke(containerOptionsBuilder);
            return(optionsBuilder);
        }
        public static MultitenancyOptionsBuilder <TTenant> ConfigureTenantMiddleware <TTenant>(
            this MultitenancyOptionsBuilder <TTenant> builder,
            Action <TenantPipelineOptionsBuilder <TTenant> > configureOptions)
            where TTenant : class
        {
            var optsBuilder = new TenantPipelineOptionsBuilder <TTenant>(builder);

            configureOptions(optsBuilder);
            return(builder);
        }
        public static MultitenancyOptionsBuilder <TTenant> ConfigureTenantFiles <TTenant>(
            this MultitenancyOptionsBuilder <TTenant> optionsBuilder,
            Action <TenantFileProviderOptionsBuilder <TTenant> > configure)
            where TTenant : class
        {
            var builder = new TenantFileProviderOptionsBuilder <TTenant>(optionsBuilder);

            configure?.Invoke(builder);
            return(optionsBuilder);
        }
        public static MultitenancyOptionsBuilder <TTenant> ConfigurePerTenantHostingEnvironment <TTenant>(
            this MultitenancyOptionsBuilder <TTenant> optionsBuilder,
            IHostingEnvironment env,
            Action <TenantHostingEnvironmentOptionsBuilder <TTenant> > configure)
            where TTenant : class
        {
            var builder = new TenantHostingEnvironmentOptionsBuilder <TTenant>(optionsBuilder, env);

            configure?.Invoke(builder);
            return(optionsBuilder);
        }
        public static IServiceProvider AddMultiTenancy <TTenant>(this IServiceCollection serviceCollection, Action <MultitenancyOptionsBuilder <TTenant> > configure)
            where TTenant : class
        {
            var optionsBuilder = new MultitenancyOptionsBuilder <TTenant>(serviceCollection);

            configure?.Invoke(optionsBuilder);

            return((optionsBuilder.ServiceProviderFactory != null)
                ? optionsBuilder.ServiceProviderFactory()
                : null);
        }
Example #6
0
        public static MultitenancyOptionsBuilder <TTenant> AddOwin <TTenant>(this MultitenancyOptionsBuilder <TTenant> builder)
            where TTenant : class
        {
            // this service will only work when
            //  IAppBuilder.UseRequestScopeContext() middleware has been activated.

            var provider = new HttpContextProvider();

            builder.HttpContextProvider = provider;
            builder.Services.AddSingleton <IHttpContextProvider>(provider);
            return(builder);
        }
        public static MultitenancyOptionsBuilder <TTenant> AddAspNetCore <TTenant>(this MultitenancyOptionsBuilder <TTenant> builder)
            where TTenant : class
        {
            var httpContextAccesser = builder.Services.FindServiceInstance <IHttpContextAccessor>();

            if (httpContextAccesser == null)
            {
                httpContextAccesser = new HttpContextAccessor();
                builder.Services.AddSingleton <IHttpContextAccessor>(httpContextAccesser);
            }

            var provider = new HttpContextProvider(httpContextAccesser);

            builder.HttpContextProvider = provider;
            builder.Services.AddSingleton <IHttpContextProvider>(provider);
            return(builder);
        }
Example #8
0
        public static IServiceProvider AddMultiTenancy <TTenant>(
            this IServiceCollection serviceCollection,
            Action <MultitenancyOptionsBuilder <TTenant> > configure)
            where TTenant : class
        {
            var optionsBuilder = new MultitenancyOptionsBuilder <TTenant>(serviceCollection);

            configure?.Invoke(optionsBuilder);

            ServiceProviderFactory = optionsBuilder.ServiceProviderFactory;

            // Cheat and feels like hack but best I can do at this time.
            TenantServiceProviderFactory <TTenant> .Factory = ServiceProviderFactory;

            return((optionsBuilder.ServiceProviderFactory != null)
                ? optionsBuilder.ServiceProviderFactory()
                : null);
        }
        public static IServiceProvider AddMultiTenancy <TTenant>(this IServiceCollection serviceCollection, Action <MultitenancyOptionsBuilder <TTenant> > configure)
            where TTenant : class
        {
            var optionsBuilder = new MultitenancyOptionsBuilder <TTenant>(serviceCollection);

            if (configure != null)
            {
                configure(optionsBuilder);
            }
            //   var serviceProvider = optionsBuilder.Build();

            Func <IServiceProvider> serviceProviderBuilder = optionsBuilder.BuildServiceProvider;

            if (serviceProviderBuilder != null)
            {
                IServiceProvider sp = serviceProviderBuilder();
                return(sp);
            }

            return(null);
            //return optionsBuilder.ServiceProvider;
        }