diff --git a/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/CookieTenantResolver.cs b/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/CookieTenantResolver.cs index 6a6ac15aa6..cbd5b25fd2 100644 --- a/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/CookieTenantResolver.cs +++ b/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/CookieTenantResolver.cs @@ -1,12 +1,13 @@ using Microsoft.AspNetCore.Http; +using Volo.Abp.MultiTenancy; namespace Volo.Abp.AspNetCore.MultiTenancy { public class CookieTenantResolver : HttpTenantResolverBase { - protected override string GetTenantIdFromHttpContextOrNull(HttpContext httpContext) + protected override string GetTenantIdFromHttpContextOrNull(ITenantResolveContext context, HttpContext httpContext) { - return httpContext.Request.Cookies[Options.TenantIdKey]; + return httpContext.Request.Cookies[context.GetAspNetCoreMultiTenancyOptions().TenantIdKey]; } } } \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/HeaderTenantResolver.cs b/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/HeaderTenantResolver.cs index 613f53ae4c..d6c01ed05b 100644 --- a/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/HeaderTenantResolver.cs +++ b/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/HeaderTenantResolver.cs @@ -1,13 +1,32 @@ -using Microsoft.AspNetCore.Http; +using System.Linq; +using Microsoft.AspNetCore.Http; +using Volo.Abp.MultiTenancy; +using Volo.ExtensionMethods.Collections.Generic; namespace Volo.Abp.AspNetCore.MultiTenancy { public class HeaderTenantResolver : HttpTenantResolverBase { - protected override string GetTenantIdFromHttpContextOrNull(HttpContext httpContext) + protected override string GetTenantIdFromHttpContextOrNull(ITenantResolveContext context, HttpContext httpContext) { //TODO: Get first one if provided multiple values and write a log - return httpContext.Request.Headers[Options.TenantIdKey]; + if (httpContext.Request.Headers.IsNullOrEmpty()) + { + return null; + } + + var tenantIdHeader = httpContext.Request.Headers[context.GetAspNetCoreMultiTenancyOptions().TenantIdKey]; + if (tenantIdHeader == string.Empty || tenantIdHeader.Count < 1) + { + return null; + } + + if (tenantIdHeader.Count > 1) + { + + } + + return tenantIdHeader.First(); } } } \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/HttpTenantResolverBase.cs b/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/HttpTenantResolverBase.cs index 7b09e90514..008c7c62e3 100644 --- a/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/HttpTenantResolverBase.cs +++ b/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/HttpTenantResolverBase.cs @@ -1,6 +1,4 @@ using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; using Volo.Abp.MultiTenancy; using Volo.ExtensionMethods; @@ -8,12 +6,8 @@ namespace Volo.Abp.AspNetCore.MultiTenancy { public abstract class HttpTenantResolverBase : ITenantResolver { - protected AspNetCoreMultiTenancyOptions Options { get; private set; } - public virtual void Resolve(ITenantResolveContext context) { - Options = context.ServiceProvider.GetRequiredService>().Value; - var httpContext = context.GetHttpContext(); if (httpContext == null) { @@ -25,13 +19,13 @@ namespace Volo.Abp.AspNetCore.MultiTenancy private void ResolveFromHttpContext(ITenantResolveContext context, HttpContext httpContext) { - var tenantId = GetTenantIdFromHttpContextOrNull(httpContext); + var tenantId = GetTenantIdFromHttpContextOrNull(context, httpContext); if (!tenantId.IsNullOrEmpty()) { context.Tenant = new TenantInfo(tenantId); } } - protected abstract string GetTenantIdFromHttpContextOrNull(HttpContext httpContext); + protected abstract string GetTenantIdFromHttpContextOrNull(ITenantResolveContext context,HttpContext httpContext); } } \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/QueryStringTenantResolver.cs b/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/QueryStringTenantResolver.cs index d50ae4e980..d928397ac7 100644 --- a/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/QueryStringTenantResolver.cs +++ b/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/QueryStringTenantResolver.cs @@ -1,17 +1,18 @@ using Microsoft.AspNetCore.Http; +using Volo.Abp.MultiTenancy; namespace Volo.Abp.AspNetCore.MultiTenancy { public class QueryStringTenantResolver : HttpTenantResolverBase { - protected override string GetTenantIdFromHttpContextOrNull(HttpContext httpContext) + protected override string GetTenantIdFromHttpContextOrNull(ITenantResolveContext context, HttpContext httpContext) { if (!httpContext.Request.QueryString.HasValue) { return null; } - return httpContext.Request.Query[Options.TenantIdKey]; + return httpContext.Request.Query[context.GetAspNetCoreMultiTenancyOptions().TenantIdKey]; } } } diff --git a/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/RouteTenantResolver.cs b/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/RouteTenantResolver.cs index 854edf2323..73414db5f1 100644 --- a/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/RouteTenantResolver.cs +++ b/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/RouteTenantResolver.cs @@ -1,14 +1,15 @@ using System; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Routing; +using Volo.Abp.MultiTenancy; namespace Volo.Abp.AspNetCore.MultiTenancy { public class RouteTenantResolver : HttpTenantResolverBase { - protected override string GetTenantIdFromHttpContextOrNull(HttpContext httpContext) + protected override string GetTenantIdFromHttpContextOrNull(ITenantResolveContext context, HttpContext httpContext) { - var tenantId = httpContext.GetRouteValue(Options.TenantIdKey); + var tenantId = httpContext.GetRouteValue(context.GetAspNetCoreMultiTenancyOptions().TenantIdKey); if (tenantId == null) { return null; diff --git a/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/TenantResolveContextExtensions.cs b/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/TenantResolveContextExtensions.cs new file mode 100644 index 0000000000..3f1d4dfe6c --- /dev/null +++ b/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/TenantResolveContextExtensions.cs @@ -0,0 +1,14 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; +using Volo.Abp.MultiTenancy; + +namespace Volo.Abp.AspNetCore.MultiTenancy +{ + public static class TenantResolveContextExtensions + { + public static AspNetCoreMultiTenancyOptions GetAspNetCoreMultiTenancyOptions(this ITenantResolveContext context) + { + return context.ServiceProvider.GetRequiredService>().Value; + } + } +} \ No newline at end of file