network-resurrector/NetworkResurrector.Agent.Do.../DependencyInjectionExtensio...

27 lines
985 B
C#
Raw Normal View History

2020-12-23 01:18:25 +02:00
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NetworkResurrector.Agent.Domain.Data.DbContexts;
using NetworkResurrector.Agent.Domain.Data.Repositories;
using NetworkResurrector.Agent.Domain.Repositories;
namespace NetworkResurrector.Agent.Domain.Data
{
public static class DependencyInjectionExtensions
{
public static void AddDataAccess(this IServiceCollection services)
{
services.AddScoped<IAgentRepository, AgentRepository>();
services
.AddDbContextPool<AgentDbContext>(
(serviceProvider, options) =>
{
var configuration = serviceProvider.GetService<IConfiguration>();
var connectionString = configuration.GetConnectionString("DatabaseConnection");
options.UseSqlServer(connectionString);
});
}
}
}