surveylib/SurveyLib.Infrastructure.EFCore/Integration/InfrastructureExtensions.cs
2025-03-15 00:10:12 +05:00

33 lines
No EOL
1.2 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using SurveyLib.Core.Repositories;
using SurveyLib.Infrastructure.EFCore.Data;
using SurveyLib.Infrastructure.EFCore.Repositories;
namespace SurveyLib.Infrastructure.EFCore.Integration;
public static class InfrastructureExtensions
{
public static IServiceCollection AddSurveyInfrastructure(this IServiceCollection services, string connectionString,
DBType dbType)
{
switch (dbType)
{
case DBType.Sqlite:
services.AddDbContext<DataContext>(options => options.UseSqlite(connectionString));
break;
case DBType.PostgreSql:
services.AddDbContext<DataContext>(options => options.UseNpgsql(connectionString));
break;
default:
throw new ArgumentOutOfRangeException(nameof(dbType), dbType, null);
}
services.AddScoped<ISurveyRepository, SurveyRepository>();
services.AddScoped<IQuestionRepository, QuestionRepository>();
services.AddScoped<ICompletionRepository, CompletionRepository>();
services.AddScoped<IAnswerRepository, AnswerRepository>();
return services;
}
}