Description:**
I am trying to implement a custom tenant resolver by extending the DomainTenantResolveContributor
in the ABP.IO framework. The goal is to resolve tenants dynamically based on the domain, using a service (ITimcheAppService
) to query tenant information from a repository.
Here is the custom tenant resolver implementation:
public class CustomDomainTenantResolveContributor : DomainTenantResolveContributor
{
private readonly ITimcheAppService _timcheAppService;
public CustomDomainTenantResolveContributor(string domainFormat, ITimcheAppService timcheAppService)
: base(domainFormat)
{
_timcheAppService = timcheAppService;
}
protected override async Task<string?> GetTenantIdOrNameFromHttpContextOrNullAsync(ITenantResolveContext context, HttpContext httpContext)
{
if (!httpContext.Request.Host.HasValue)
{
return null;
}
var domain = httpContext.Request.Host.Host;
// Query the service for tenant information
var tenantName = await _timcheAppService.FindTenantNameByDomainAsync(domain);
if (tenantName == null)
{
return null; // No tenant resolved
}
context.Handled = true;
return tenantName; // Return tenant name for ABP to resolve
}
}
I attempted to register this custom contributor in the ConfigureServices
method as follows:
Configure<AbpTenantResolveOptions>(options =>
{
options.AddContributor(serviceProvider =>
{
var timcheAppService = serviceProvider.GetRequiredService<ITimcheAppService>();
// Add the CustomDomainTenantResolveContributor
return new CustomDomainTenantResolveContributor("{0}", timcheAppService);
});
});
However, the resolver is not working as expected. Tenant resolution does not trigger this contributor, and I suspect there might be an issue with how DomainTenantResolveContributor
is being used as a base class.
DomainTenantResolveContributor
.Configure<AbpTenantResolveOptions>
.The CustomDomainTenantResolveContributor
should be invoked during tenant resolution, dynamically fetching tenant information from the service and resolving the tenant correctly.
The custom contributor is not triggered during tenant resolution.
I noticed that DomainTenantResolveContributor
works fine when used directly, but custom extensions or overrides seem to fail when registered using AddContributor
.
Please clarify:
DomainTenantResolveContributor
for custom logic?Configure<AbpTenantResolveOptions>
?