31 lines
1.1 KiB
C#
31 lines
1.1 KiB
C#
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<ITextSubscriptionRepository, TextSubscriptionRepository>();
|
|
|
|
services.AddDbContext<TextMatcherContext>(
|
|
(ctx, context) =>
|
|
{
|
|
context.UseMySql(connectionString, new MariaDbServerVersion(MariaDbServerVersion.LatestSupportedServerVersion))
|
|
.UseLoggerFactory(ctx.GetRequiredService<ILoggerFactory>());
|
|
}
|
|
);
|
|
|
|
return services;
|
|
}
|
|
} |