- Added central AddEnvelopeGenerator extension to aggregate existing DI setups - Introduced EGConfiguration for modular service registration - Standardized configuration pattern for Application and Infrastructure layers - Simplified distributed cache and localization registration
70 lines
2.2 KiB
C#
70 lines
2.2 KiB
C#
using DigitalData.EmailProfilerDispatcher;
|
|
using DigitalData.UserManager.DependencyInjection;
|
|
using EnvelopeGenerator.Application;
|
|
using EnvelopeGenerator.Infrastructure;
|
|
using Microsoft.Extensions.Caching.SqlServer;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using static EnvelopeGenerator.Infrastructure.DependencyInjection;
|
|
|
|
namespace EnvelopeGenerator.DependencyInjection;
|
|
|
|
public static class DependencyInjection
|
|
{
|
|
public static IServiceCollection AddEnvelopeGenerator(this IServiceCollection services, IConfiguration config, Action<EGConfiguration> options, Action<SqlServerCacheOptions> distributedCacheOptions)
|
|
{
|
|
var egConfig = new EGConfiguration();
|
|
options.Invoke(egConfig);
|
|
egConfig.RegisterAll(services);
|
|
|
|
// Add envelope generator services
|
|
#pragma warning disable CS0618
|
|
services.AddUserManager<EGDbContext>();
|
|
#pragma warning restore CS0618
|
|
|
|
services.AddDispatcher<EGDbContext>();
|
|
|
|
return services;
|
|
}
|
|
|
|
public record EGConfiguration
|
|
{
|
|
internal readonly Queue<Action<IServiceCollection>> ServiceRegs = new();
|
|
|
|
internal void RegisterAll(IServiceCollection services)
|
|
{
|
|
while (ServiceRegs.Count > 0)
|
|
ServiceRegs.Dequeue().Invoke(services);
|
|
}
|
|
|
|
public EGConfiguration AddLocalization()
|
|
{
|
|
ServiceRegs.Enqueue(s => s.AddLocalization());
|
|
return this;
|
|
}
|
|
|
|
public EGConfiguration AddDistributedSqlServerCache(Action<SqlServerCacheOptions> setupAction)
|
|
{
|
|
ServiceRegs.Enqueue(s => s.AddDistributedSqlServerCache(setupAction));
|
|
return this;
|
|
}
|
|
|
|
public EGConfiguration AddInfrastructure(Action<EGInfrastructureConfiguration> options)
|
|
{
|
|
#pragma warning disable CS0618
|
|
ServiceRegs.Enqueue(s => s.AddEGInfrastructureServices(options));
|
|
#pragma warning restore CS0618
|
|
return this;
|
|
}
|
|
|
|
public IConfiguration Configuration
|
|
{
|
|
set
|
|
{
|
|
#pragma warning disable CS0618
|
|
ServiceRegs.Enqueue(s => s.AddEnvelopeGeneratorServices(value));
|
|
#pragma warning restore CS0618
|
|
}
|
|
}
|
|
}
|
|
} |