chatbot/Chatbot.Api.Domain.Data/DependencyInjectionExtensio...

47 lines
1.8 KiB
C#
Raw Permalink Normal View History

2020-06-06 18:29:20 +03:00
using Chatbot.Api.Domain.Data.DbContexts;
using Chatbot.Api.Domain.Data.Repositories;
using Chatbot.Api.Domain.Repositories;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;
namespace Chatbot.Api.Domain.Data
{
public static class DependencyInjectionExtensions
{
public static void AddDataAccess(this IServiceCollection services)
{
services.AddScoped<IBotRepository, BotRepository>();
2020-06-06 19:21:40 +03:00
services.AddScoped<ISessionRepository, SessionRepository>();
2020-06-06 23:18:41 +03:00
services.AddScoped<IChatRepository, ChatRepository>();
2020-06-06 18:29:20 +03:00
services
.AddDbContextPool<BotDbContext>(
(serviceProvider, options) =>
{
var configuration = serviceProvider.GetService<IConfiguration>();
var connectionString = configuration.GetConnectionString("DatabaseConnection");
options.UseSqlServer(connectionString);
});
2020-06-06 19:21:40 +03:00
services
.AddDbContextPool<SessionDbContext>(
(serviceProvider, options) =>
{
var configuration = serviceProvider.GetService<IConfiguration>();
var connectionString = configuration.GetConnectionString("DatabaseConnection");
options.UseSqlServer(connectionString);
});
2020-06-06 23:18:41 +03:00
services
.AddDbContextPool<ChatDbContext>(
(serviceProvider, options) =>
{
var configuration = serviceProvider.GetService<IConfiguration>();
var connectionString = configuration.GetConnectionString("DatabaseConnection");
options.UseSqlServer(connectionString);
});
2020-06-06 18:29:20 +03:00
}
}
}