using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Nocr.TextMatcher.AppServices.TextSubscriptions.Repositories; using Nocr.TextMatcher.Persistence.TextSubscriptions; namespace Nocr.TextMatcher.Persistence; public static class ServiceCollectionExtensions { public static IServiceCollection AddEfPersistence(this IServiceCollection services, string connectionString) { if (services == null) throw new ArgumentNullException(nameof(services)); if (string.IsNullOrWhiteSpace(connectionString)) throw new ArgumentNullException(nameof(connectionString)); services.AddScoped(); services.AddDbContext( (ctx, context) => { context.UseMySql(connectionString, new MariaDbServerVersion(MariaDbServerVersion.LatestSupportedServerVersion)) .UseLoggerFactory(ctx.GetRequiredService()); } ); return services; } }