public async Task Invoke(HttpContext context, IOptions <TenantsConfiguration> tenantsConfiguration)
 {
     this.TenantsConfiguration = tenantsConfiguration.Value;
     using (this.Logger.BeginScope("TenantResolverMiddleware"))
     {
         string subdomain = this.GetSubdomain(context);
         var    tenant    = this.TenantsConfiguration.Find(subdomain);
         this.Logger.LogInformation($"Resolved tenant. Current tenant: {tenant.Id}");
         var tenantFeature = new TenantFeature(tenant);
         context.Features.Set <ITenantFeature>(tenantFeature);
         await this.Next(context).ConfigureAwait(true);
     }
 }
Exemplo n.º 2
0
        private TenantsConfiguration ResolveConfiguration(IConfigurationSection configuration)
        {
            var config  = new TenantsConfiguration();
            var tenants = new List <TenantConfiguration>();

            foreach (var section in configuration.GetSection("tenants").GetChildren())
            {
                string id     = section.Key;
                var    tenant = new TenantConfiguration()
                {
                    Id        = id,
                    HostNames = section.GetSection("hostnames").AsEnumerable().Skip(1).Select(p => p.Value).ToArray()
                };

                tenants.Add(tenant);
            }

            return(new TenantsConfiguration
            {
                Tenants = tenants.ToArray()
            });
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Tenants"/> class.
 /// </summary>
 /// <param name="configuration">The <see cref="TenantsConfiguration">configuration</see> for tenants.</param>
 public Tenants(IOptions <TenantsConfiguration> configuration)
 {
     _configuration = configuration.Value;
 }