diff --git a/.gitignore b/.gitignore index 4002754..b45c758 100644 --- a/.gitignore +++ b/.gitignore @@ -361,6 +361,6 @@ MigrationBackup/ # Fody - auto-generated XML schema FodyWeavers.xsd -/.vs/ApiPolo/DesignTimeBuild/.dtbcache.v2 /.vs/ApiPolo/v17/.suo /.vs/ApiPolo/v17/.futdcache.v2 +/.vs/ApiPolo/DesignTimeBuild/.dtbcache.v2 diff --git a/ApiPolo/Interfaces/TenantDbContextFactory.cs b/ApiPolo/Interfaces/TenantDbContextFactory.cs index aed0627..58c790e 100644 --- a/ApiPolo/Interfaces/TenantDbContextFactory.cs +++ b/ApiPolo/Interfaces/TenantDbContextFactory.cs @@ -14,16 +14,15 @@ public class TenantDbContextFactory : ITenantDbContextFactory public ITenantDbContext GetDbContext(string tenant) { // Create a scope to resolve DbContext - using (var scope = _serviceProvider.CreateScope()) + var scope = _serviceProvider.CreateScope(); + + return tenant switch { - return tenant switch - { - Clienti.Maras => scope.ServiceProvider.GetRequiredService(), - Clienti.Marrocco => scope.ServiceProvider.GetRequiredService(), - // Add other tenants as needed - // Clienti.AnotherTenant => scope.ServiceProvider.GetRequiredService(), - _ => throw new KeyNotFoundException($"No DbContext found for tenant: {tenant}") - }; - } + Clienti.Maras => scope.ServiceProvider.GetRequiredService(), + Clienti.Marrocco => scope.ServiceProvider.GetRequiredService(), + // Add other tenants as needed + // Clienti.AnotherTenant => scope.ServiceProvider.GetRequiredService(), + _ => throw new KeyNotFoundException($"No DbContext found for tenant: {tenant}") + }; } }