示例#1
0
        public async Task Invoke(HttpContext context, ITenantResolver tenantResolver)
        {
            tenantsHost.Initialize();

            logger.LogDebug($"Resolving Tenant using \"{tenantResolver.GetType().FullName}\".");
            var tenant = await tenantResolver.ResolveAsync(context);

            if (tenant != null)
            {
                logger.LogDebug("Start getting TenantContext from TenantsHost.");

                var tenantContext = tenantsHost.GetOrCreateContext(tenant);
                context.SetTenantContext(tenantContext);
                logger.LogDebug("Getting TenantContext successful and set to HttpContext.");

                using (var scope = tenantContext.EnterServiceScope())
                {
                    await next.Invoke(context);
                }
            }
            else if (tenantsConfig.UnresolvedRedirect.HasValue())
            {
                logger.LogDebug($"Tenant resolved failure. Now redreact to url: {tenantsConfig.UnresolvedRedirect}.");
                Redirect(context, tenantsConfig.UnresolvedRedirect, tenantsConfig.RedirectPermanent);
            }
            else
            {
                await next.Invoke(context);
            }
        }
示例#2
0
        public async Task Invoke(HttpContext context, ITenantResolver <TTenant> tenantResolver)
        {
            log.LogDebug("Resolving TenantContext using {loggerType}.", tenantResolver.GetType().Name);

            var tenantContext = await tenantResolver.Resolve(context);

            if (tenantContext != null)
            {
                log.LogDebug("TenantContext Resolved. Adding to HttpContext.");
                context.SetTenantContext(tenantContext);
            }
            else
            {
                log.LogDebug("TenantContext Not Resolved.");
            }

            await next.Invoke(context);
        }
示例#3
0
        public async Task Invoke(HttpContext context, ITenantResolver tenantResolver)
        {
            logger.LogDebug("Resolving TenantContext using {loggerType}.", tenantResolver.GetType().Name);

            var tenantContext = await tenantResolver.ResolveAsync(context);

            if (tenantContext != null)
            {
                logger.LogDebug("TenantContext resolved successful. Adding to HttpContext.");
                context.SetTenantContext(tenantContext);
            }
            else if (tenantsConfig.UnresolvedRedirect.HasValue())
            {
                logger.LogDebug("TenantContext resolved failure. Now redreact to unresolved url.");
                Redirect(context, tenantsConfig.UnresolvedRedirect, tenantsConfig.RedirectPermanent);
                return;
            }

            await next.Invoke(context);
        }
示例#4
0
        public async Task Invoke(HttpContext context, ITenantResolver <TTenant> tenantResolver)
        {
            Ensure.Argument.NotNull(context, nameof(context));
            Ensure.Argument.NotNull(tenantResolver, nameof(tenantResolver));

            log.LogDebug("Resolving TenantContext using {loggerType}.", tenantResolver.GetType().Name);

            var tenantContext = await tenantResolver.ResolveAsync(context);

            if (tenantContext != null)
            {
                log.LogVerbose("TenantContext Resolved. Adding to HttpContext.");
                context.SetTenantContext(tenantContext);
            }
            else
            {
                log.LogDebug("TenantContext Not Resolved.");
            }

            await next.Invoke(context);
        }
        public async Task Invoke(
            HttpContext httpContext,
            ILog <TenantResolutionMiddleware <TTenant> > logger,
            ITenantResolver <TTenant> tenantResolver)
        {
            logger?.Debug($"Resolving TenantContext using {tenantResolver.GetType().Name}.");
            TenantContext <TTenant> tenantContext = await tenantResolver.ResolveAsync(httpContext).ConfigureAwait(false);

            if (tenantContext != null)
            {
                logger?.Debug("TenantContext Resolved. Adding to HttpContext.");
                httpContext?.SetTenantContext(tenantContext);
            }
            else
            {
                logger?.Warn("TenantContext Not Resolved.");
            }

            //using (logger.Info($"Tenant:{httpContext.GetTenant<TTenant>()}"))
            {
                await next.Invoke(httpContext).ConfigureAwait(false);
            }
        }
        public async Task Invoke(HttpContext context, ITenantResolver resolver, IConfiguration configuration,
                                 IServiceProvider provider)
        {
            Guard.ArgumentNotNull(context, nameof(context));
            Guard.ArgumentNotNull(resolver, nameof(resolver));
            Guard.ArgumentNotNull(configuration, nameof(configuration));

            _logger.LogDebug("Resolving Tenant using {loggerType}.", resolver.GetType().Name);

            var tenant = await resolver.ResolveAsync(context);

            if (tenant != null)
            {
                _logger.LogDebug("Tenant Resolved. Adding to HttpContext.");

                context.SetTenantContext(new TenantContext(tenant));
            }
            else
            {
                _logger.LogDebug("Tenant Not Resolved.");
            }

            await _next.Invoke(context);
        }