37 lines
1.4 KiB
C#
37 lines
1.4 KiB
C#
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>();
|
|
services.AddScoped<ISessionRepository, SessionRepository>();
|
|
|
|
services
|
|
.AddDbContextPool<BotDbContext>(
|
|
(serviceProvider, options) =>
|
|
{
|
|
var configuration = serviceProvider.GetService<IConfiguration>();
|
|
var connectionString = configuration.GetConnectionString("DatabaseConnection");
|
|
options.UseSqlServer(connectionString);
|
|
});
|
|
|
|
services
|
|
.AddDbContextPool<SessionDbContext>(
|
|
(serviceProvider, options) =>
|
|
{
|
|
var configuration = serviceProvider.GetService<IConfiguration>();
|
|
var connectionString = configuration.GetConnectionString("DatabaseConnection");
|
|
options.UseSqlServer(connectionString);
|
|
});
|
|
}
|
|
}
|
|
}
|