added integration tools
This commit is contained in:
parent
7c30a3599f
commit
bac3ed072e
3 changed files with 42 additions and 0 deletions
7
SurveyLib.Infrastructure.EFCore/Integration/DBType.cs
Normal file
7
SurveyLib.Infrastructure.EFCore/Integration/DBType.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
namespace SurveyLib.Infrastructure.EFCore.Integration;
|
||||
|
||||
public enum DBType
|
||||
{
|
||||
Sqlite,
|
||||
PostgreSql
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,8 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.3" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.3" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue