36 lines
1.5 KiB
C#
36 lines
1.5 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Solicitors.Core;
|
|
using Solicitors.Core.Data;
|
|
using Solicitors.Data.RepositorySetup;
|
|
using Solicitors.Data.RepositorySetup.InMemory;
|
|
using Solicitors.Data.RepositorySetup.Sqlite;
|
|
|
|
namespace Solicitors.Data;
|
|
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
public static class DIExtensions
|
|
{
|
|
public static IServiceCollection AddData(this IServiceCollection services, IRepoSetupOptions options)
|
|
{
|
|
return services
|
|
.AddScoped<SolicitorsRepository>()
|
|
.AddScoped<ISolicitorRepository>(sp => sp.GetRequiredService<SolicitorsRepository>())
|
|
.AddScoped<IReadOnlySolicitorRepository>(sp => sp.GetRequiredService<ISolicitorRepository>())
|
|
.AddScoped<IReadOnlyCitiesRepository>(sp => sp.GetRequiredService<SolicitorsRepository>())
|
|
.AddScoped<IRatingsProviderRepository>(sp => sp.GetRequiredService<SolicitorsRepository>())
|
|
.AddSingleton(GetSetupService(options));
|
|
}
|
|
|
|
private static IRepoSetupService GetSetupService(IRepoSetupOptions options)
|
|
{
|
|
if (options is InMemoryDbSetupOptions inMemOptions)
|
|
return new InMemorySetupService(inMemOptions);
|
|
|
|
if (options is SqliteDbSetupOptions sqliteOptions)
|
|
return new SqliteSetupService(sqliteOptions);
|
|
|
|
throw new ArgumentException("Options type not supported", nameof(options));
|
|
}
|
|
} |