PI06 i PI06-1. Docker definitions for MSSQL and Postgres. Data seeder/generator for countries and people. Entity Framework example with variants for Postgres and MSSQL
This commit is contained in:
32
DataAccess/EF_Demo/DISetup.cs
Normal file
32
DataAccess/EF_Demo/DISetup.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user