diff --git a/src/ReC.Infrastructure/DependencyInjection.cs b/src/ReC.Infrastructure/DependencyInjection.cs new file mode 100644 index 0000000..0ab5890 --- /dev/null +++ b/src/ReC.Infrastructure/DependencyInjection.cs @@ -0,0 +1,31 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; + +namespace ReC.Infrastructure; + +public static class DependencyInjection +{ + public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, Action options) + { + var configOpt = new ConfigurationOptions(); + options.Invoke(configOpt); + + if(configOpt.DbContextOptionsAction is null) + throw new InvalidOperationException("DbContextOptionsAction must be configured."); + + services.AddDbContext(configOpt.DbContextOptionsAction); + + return services; + } + + public class ConfigurationOptions + { + internal Action? DbContextOptionsAction { get; private set; } + + public ConfigurationOptions ConfigureDbContext(Action optionsAction) + { + DbContextOptionsAction = optionsAction; + return this; + } + } +} diff --git a/src/ReC.Infrastructure/ReC.Infrastructure.csproj b/src/ReC.Infrastructure/ReC.Infrastructure.csproj index 987f78b..5ce4d9b 100644 --- a/src/ReC.Infrastructure/ReC.Infrastructure.csproj +++ b/src/ReC.Infrastructure/ReC.Infrastructure.csproj @@ -8,6 +8,7 @@ +