Tenant resolved interceptor
It is possible to perform a process once the tenant has been resolved.
The tenant has been resolved when the user logs in and one of these conditions is valid:
- The application is not multi-tenant.
- The user has only one tenant.
- The user has several tenants and he has selected a tenant via the selection page.
An interceptor allows you to instantiate the application context, theme and languages.
There may be several interceptors per cluster.
The order in which interceptors are executed depends on the dependencies between modules. If two independent modules implement an interceptor, the order of execution is not guaranteed.
Implement the interceptor
First, you need to create a new class that implements the ITenantResolvedInterceptor
interface.
Example of an implementation :
internal class TenantResolvedInterceptor : ITenantResolvedInterceptor
{
public async Task<OnTenantResolvedResult> OnTenantResolvedAsync(NeosTenantInfo? tenant, OnTenantResolvedResult previousTenantResolvedResult)
{
return previousTenantResolvedResult
.WithContextValue("Value", 123)
.WithTheme("AcmeTheme");
}
}
In this example, a value is added to the application context and the theme is defined.
It is possible to inject services into this class (such as repositories).
The previousTenantResolvedResult
variable contains the result of previous interceptors. Although this is not recommended, an interceptor can override this result by returning a new OnTenantResolvedResult
instance.
Register the interceptor
Once the interceptor has been created, you need to create or update the Startup
class at the root of the project and register it in the ConfigureServices
method using the AddTenantResolvedInterceptor
method :
public static class Startup
{
public static void ConfigureServices(IServiceCollection services)
{
services.AddTenantResolvedInterceptor<TenantResolvedInterceptor>();
}
}