-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Description
Hi,
I want change strategy for MutliTenant with WithHostStrategy. I added .WithHostStrategy("*.tenant.?") keyword like below and load tenant list from config file. but I get authentication error.
What is your suggetions?
@fretje @justSteve @pashaie @maxiar @geekz-reno @iammukeshm
regards
ArgumentNullException.ThrowIfNull(services);
_ = services.AddTransient<IConnectionStringValidator, ConnectionStringValidator>();
_ = services.BindDbContext<TenantDbContext>();
_ = services.AddMultiTenant<FshTenantInfo>(config =>
{
// to save database calls to resolve tenant
// this was happening for every request earlier, leading to ineffeciency
config.Events.OnTenantResolveCompleted = async (context) =>
{
if (context.MultiTenantContext.StoreInfo is null) return;
if (context.MultiTenantContext.StoreInfo.StoreType != typeof(DistributedCacheStore<FshTenantInfo>))
{
var sp = ((HttpContext)context.Context!).RequestServices;
var distributedCacheStore = sp
.GetService<IEnumerable<IMultiTenantStore<FshTenantInfo>>>()!
.FirstOrDefault(s => s.GetType() == typeof(DistributedCacheStore<FshTenantInfo>));
_ = await distributedCacheStore!.TryAddAsync(context.MultiTenantContext.TenantInfo!);
}
await Task.FromResult(0);
};
})
.WithHostStrategy("*.__tenant__.?")
// removed other strategies
.WithConfigurationStore() // load from config file
.WithDistributedCacheStore(TimeSpan.FromMinutes(60))
.WithEFCoreStore<TenantDbContext, FshTenantInfo>();
_ = services.AddScoped<ITenantService, TenantService>();
return services;
part of appseting.config file:
...
"Finbuckle:MultiTenant:Stores:ConfigurationStore": {
"Tenants": [
{
"Id": "root",
"Identifier": "root",
"Name": "Root Tenant",
"ConnectionString": ""
},
{
"Id": "tenant2 ",
"Identifier": "tenant2 ",
"Name": "Second Tenant",
"ConnectionString": ""
}
]
}
Metadata
Metadata
Assignees
Labels
No labels