using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using ApiPolo.Interfaces; using System; using System.Collections.Generic; using static ApiPolo.Controllers.PoloController; using ApiPolo.Data; namespace ApiPolo.Services { public class TenantDbContextFactory : ITenantDbContextFactory { private readonly IServiceProvider _serviceProvider; public TenantDbContextFactory(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; } public ITenantDbContext GetDbContext(string tenant) { return tenant switch { Clienti.Maras => _serviceProvider.GetRequiredService(), // Add other tenants as needed // Clienti.AnotherTenant => _serviceProvider.GetRequiredService(), _ => throw new KeyNotFoundException($"No DbContext found for tenant: {tenant}") }; } } }