33 lines
1.3 KiB
C#
33 lines
1.3 KiB
C#
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<Program>()
|
|
.Build();
|
|
|
|
IServiceCollection services = new ServiceCollection();
|
|
|
|
var provider = services.AddLogging(configure => {
|
|
configure.AddConfiguration(configuration.GetSection("Logging"));
|
|
configure.AddConsole();
|
|
})
|
|
.AddDbContext<Data.MSSQL.EventsContext>(options => {
|
|
options.UseSqlServer(configuration.GetConnectionString("EventsMssql"));
|
|
}, contextLifetime: ServiceLifetime.Transient)
|
|
.AddDbContext<Data.Postgres.EventsContext>(options => {
|
|
options.UseNpgsql(configuration.GetConnectionString("EventsPostgres"));
|
|
}, contextLifetime: ServiceLifetime.Transient)
|
|
.BuildServiceProvider();
|
|
return provider;
|
|
}
|
|
}
|