using System.Diagnostics.CodeAnalysis; using FruityFoundation.DataAccess.Abstractions; using Microsoft.Extensions.DependencyInjection; namespace FruityFoundation.DataAccess.Sqlite; [ExcludeFromCodeCoverage(Justification = "Dependency injection helpers")] public static class ServiceCollectionExtensions { public static void AddSqliteDataAccess( this IServiceCollection services, Func getReadWriteConnectionString, Func getReadOnlyConnectionString ) { services.AddScoped>(serviceProvider => { var connectionFactory = serviceProvider.GetRequiredService(); return connectionFactory.CreateConnection(); }); services.AddScoped>(serviceProvider => { var connectionFactory = serviceProvider.GetRequiredService(); return connectionFactory.CreateReadOnlyConnection(); }); services.AddSingleton(serviceProvider => new SqliteDbConnectionFactory( serviceProvider, getReadOnlyConnectionString: getReadOnlyConnectionString, getReadWriteConnectionString: getReadWriteConnectionString)); } }