using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; namespace EF_Demo; internal class DISetup { public static ServiceProvider BuildDI() { var configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .AddUserSecrets() .Build(); IServiceCollection services = new ServiceCollection(); var provider = services.AddLogging(configure => { configure.AddConfiguration(configuration.GetSection("Logging")); configure.AddConsole(); }) .AddDbContext(options => { options.UseSqlServer(configuration.GetConnectionString("EventsMssql")); }, contextLifetime: ServiceLifetime.Transient) .AddDbContext(options => { options.UseNpgsql(configuration.GetConnectionString("EventsPostgres")); }, contextLifetime: ServiceLifetime.Transient) .BuildServiceProvider(); return provider; } }