persistence/Persistence.Database.Postgres/DependencyInjection.cs

23 lines
759 B
C#
Raw Normal View History

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