29 lines
1002 B
C#
29 lines
1002 B
C#
using ApiPolo.Data;
|
|
using ApiPolo.Interfaces;
|
|
using static ApiPolo.Controllers.PoloController;
|
|
|
|
public class TenantDbContextFactory : ITenantDbContextFactory
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
public TenantDbContextFactory(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
}
|
|
|
|
public ITenantDbContext GetDbContext(string tenant)
|
|
{
|
|
// Create a scope to resolve DbContext
|
|
var scope = _serviceProvider.CreateScope();
|
|
|
|
return tenant switch
|
|
{
|
|
//Clienti.Maras => scope.ServiceProvider.GetRequiredService<Maras_DbContext>(),
|
|
//Clienti.Marrocco => scope.ServiceProvider.GetRequiredService<Marro_DbContext>(),
|
|
//// Add other tenants as needed
|
|
//// Clienti.AnotherTenant => scope.ServiceProvider.GetRequiredService<AnotherTenant_DbContext>(),
|
|
//_ => throw new KeyNotFoundException($"No DbContext found for tenant: {tenant}")
|
|
};
|
|
}
|
|
}
|