From bac3ed072e388e010d31edcc21073a2b87f3fa9e Mon Sep 17 00:00:00 2001 From: shept Date: Sat, 15 Mar 2025 00:10:12 +0500 Subject: [PATCH] added integration tools --- .../Integration/DBType.cs | 7 ++++ .../Integration/InfrastructureExtensions.cs | 33 +++++++++++++++++++ .../SurveyLib.Infrastructure.EFCore.csproj | 2 ++ 3 files changed, 42 insertions(+) create mode 100644 SurveyLib.Infrastructure.EFCore/Integration/DBType.cs create mode 100644 SurveyLib.Infrastructure.EFCore/Integration/InfrastructureExtensions.cs diff --git a/SurveyLib.Infrastructure.EFCore/Integration/DBType.cs b/SurveyLib.Infrastructure.EFCore/Integration/DBType.cs new file mode 100644 index 0000000..f498c86 --- /dev/null +++ b/SurveyLib.Infrastructure.EFCore/Integration/DBType.cs @@ -0,0 +1,7 @@ +namespace SurveyLib.Infrastructure.EFCore.Integration; + +public enum DBType +{ + Sqlite, + PostgreSql +} \ No newline at end of file diff --git a/SurveyLib.Infrastructure.EFCore/Integration/InfrastructureExtensions.cs b/SurveyLib.Infrastructure.EFCore/Integration/InfrastructureExtensions.cs new file mode 100644 index 0000000..4735df6 --- /dev/null +++ b/SurveyLib.Infrastructure.EFCore/Integration/InfrastructureExtensions.cs @@ -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(options => options.UseSqlite(connectionString)); + break; + case DBType.PostgreSql: + services.AddDbContext(options => options.UseNpgsql(connectionString)); + break; + default: + throw new ArgumentOutOfRangeException(nameof(dbType), dbType, null); + } + + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + + return services; + } +} \ No newline at end of file diff --git a/SurveyLib.Infrastructure.EFCore/SurveyLib.Infrastructure.EFCore.csproj b/SurveyLib.Infrastructure.EFCore/SurveyLib.Infrastructure.EFCore.csproj index 08f712f..e154bcc 100644 --- a/SurveyLib.Infrastructure.EFCore/SurveyLib.Infrastructure.EFCore.csproj +++ b/SurveyLib.Infrastructure.EFCore/SurveyLib.Infrastructure.EFCore.csproj @@ -8,6 +8,8 @@ + +