private RequestDelegate BuildTenantPipeline(HttpContext httpContext, TenantContext <TTenant> tenantContext, ILog <TenantPipelineMiddleware <TTenant> > loggerPipeline)
        {
            loggerPipeline.Info($" Building TenantPipeline for Tenant: {tenantContext.Id}");
            IApplicationBuilder branchBuilder = rootApp.New();
            TenantPipelineBuilderContext <TTenant> builderContext = new TenantPipelineBuilderContext <TTenant>(tenantContext);

            IServiceProvider provider = serviceFactoryForMultitenancy.Build(tenantContext);

            branchBuilder.Use(async(context, next) =>
            {
                IServiceScopeFactory factory = provider.GetRequiredService <IServiceScopeFactory>();
                using (IServiceScope scope = factory.CreateScope())
                {
                    context.RequestServices = scope.ServiceProvider;
                    await next().ConfigureAwait(false);
                }
            });

            branchBuilder.ApplicationServices = provider;
            configuration(builderContext, branchBuilder);

            // register root pipeline at the end of the tenant branch
            branchBuilder.Run(next);

            RequestDelegate branchDelegate = branchBuilder.Build();

            loggerPipeline.Info($" Builded TenantPipeline for Tenant: {tenantContext.Id}");
            return(branchDelegate);
        }
Esempio n. 2
0
        private RequestDelegate BuildTenantPipeline(TenantContext <TTenant> tenantContext)
        {
            var branchBuilder = rootApp.New();

            var builderContext = new TenantPipelineBuilderContext <TTenant>
            {
                TenantContext = tenantContext,
                Tenant        = tenantContext.Tenant
            };

            configuration(builderContext, branchBuilder);

            // register root pipeline at the end of the tenant branch
            branchBuilder.Run(next);

            return(branchBuilder.Build());
        }
Esempio n. 3
0
        protected virtual Task <RequestDelegate> BuildTenantPipeline(IApplicationBuilder rootApp, TTenant tenant, RequestDelegate next)
        {
            return(Task.Run(() =>
            {
                var branchBuilder = rootApp.New();
                var builderContext = new TenantPipelineBuilderContext <TTenant>
                {
                    Tenant = tenant
                };

                _configuration(builderContext, branchBuilder);

                // register root pipeline at the end of the tenant branch
                branchBuilder.Run(next);
                return branchBuilder.Build();
            }));
        }
        protected virtual RequestDelegate BuildTenantPipeline(IApplicationBuilder rootApp, TTenant tenant, IServiceProvider requestServices, RequestDelegate next)
        {
            var branchBuilder = rootApp.New();

            rootApp.ApplicationServices = requestServices;
            var builderContext = new TenantPipelineBuilderContext <TTenant>
            {
                //   TenantContext = tenantContext,
                Tenant = tenant
            };

            _configuration(builderContext, branchBuilder);

            // register root pipeline at the end of the tenant branch
            branchBuilder.Run(next);
            return(branchBuilder.Build());
        }
        protected virtual Task <RequestDelegate> UseTenantPipeline(IApplicationBuilder rootApp, IServiceProvider serviceProviderOverride, TTenant tenant, RequestDelegate next, bool reJoin)
        {
            return(Task.Run(() =>
            {
                var branchBuilder = rootApp.New();
                branchBuilder.ApplicationServices = serviceProviderOverride;
                var builderContext = new TenantPipelineBuilderContext <TTenant>
                {
                    Tenant = tenant
                };

                _configuration(builderContext, branchBuilder);

                // register root pipeline at the end of the tenant branch
                if (next != null && reJoin)
                {
                    branchBuilder.Run(next);
                }
                return branchBuilder.Build();
            }));
        }
Esempio n. 6
0
        protected virtual Task <AppFunc> UseTenantPipeline(IAppBuilder rootApp, IServiceProvider serviceProviderOverride, TTenant tenant, AppFunc next, bool reJoin)
        {
            return(Task.Run(() =>
            {
                var branchBuilder = rootApp.New();
                branchBuilder.Properties["ApplicationServices"] = serviceProviderOverride;
                //branchBuilder.ApplicationServices = serviceProviderOverride;
                var builderContext = new TenantPipelineBuilderContext <TTenant>
                {
                    Tenant = tenant
                };

                _configuration(builderContext, branchBuilder);

                // register root pipeline at the end of the tenant branch
                if (next != null && reJoin)
                {
                    branchBuilder.Use(typeof(ReJoinMiddleware), next);
                }

                var result = (AppFunc)branchBuilder.Build(typeof(AppFunc));
                return result;
            }));
        }