persistence/Persistence.Database.Postgres/DependencyInjection.cs
ngfrolov 980d3100af
Добавил отдельный контекст не привязанный к конкретной БД.
Поправил скрипт инициализации.
Пересоздао миграции.
2024-11-26 15:07:18 +05:00

21 lines
709 B
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace Persistence.Database.Model;
public static class DependencyInjection
{
public static IServiceCollection AddPersistenceDbContext(this IServiceCollection services, IConfiguration configuration)
{
string connectionStringName = "DefaultConnection";
services.AddDbContext<PersistencePostgresContext>(options =>
options.UseNpgsql(configuration.GetConnectionString(connectionStringName)));
services.AddScoped<DbContext>(provider => provider.GetRequiredService<PersistencePostgresContext>());
return services;
}
}