Refactor service registration for modularity
Introduced `EnvelopeGeneratorOptions` and `SqlCacheOptions` to enable fine-grained control over optional service registrations in `AddEnvelopeGenerator`. Updated `AddEnvelopeGenerator` to conditionally register services like `HttpContextAccessor`, `DistributedSqlServerCache`, `Dispatcher`, `MemoryCache`, and `UserManager` based on these options. Updated `DependencyInjection.csproj` to include necessary framework references and package dependencies. Simplified `Program.cs` by consolidating service registrations into `AddEnvelopeGenerator`, reducing boilerplate and improving maintainability. Improved extensibility by centralizing service registration logic, allowing consuming projects to customize configurations without modifying the core library. Updated documentation and removed unused directives.
This commit is contained in:
@@ -12,7 +12,6 @@ using DigitalData.EmailProfilerDispatcher;
|
||||
using EnvelopeGenerator.Infrastructure;
|
||||
using EnvelopeGenerator.Web.Sanitizers;
|
||||
using EnvelopeGenerator.Web.Models.Annotation;
|
||||
using DigitalData.UserManager.DependencyInjection;
|
||||
using EnvelopeGenerator.Web.Middleware;
|
||||
using EnvelopeGenerator.DependencyInjection;
|
||||
using EnvelopeGenerator.Web;
|
||||
@@ -55,8 +54,6 @@ try
|
||||
});
|
||||
});
|
||||
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
|
||||
builder.ConfigureBySection<TFARegParams>();
|
||||
|
||||
// Add controllers and razor views
|
||||
@@ -93,26 +90,29 @@ try
|
||||
var connStr = config.GetConnectionString(cnnStrName)
|
||||
?? throw new InvalidOperationException($"Connection string '{cnnStrName}' is missing in the application configuration.");
|
||||
|
||||
builder.Services.AddDistributedSqlServerCache(options =>
|
||||
{
|
||||
options.ConnectionString = connStr;
|
||||
options.SchemaName = "dbo";
|
||||
options.TableName = "TBDD_CACHE";
|
||||
});
|
||||
|
||||
// Add envelope generator services
|
||||
builder.Services.AddEnvelopeGenerator(config, opt =>
|
||||
{
|
||||
opt.AddDbTriggerParams(config);
|
||||
opt.AddDbContext((provider, options) =>
|
||||
builder.Services.AddEnvelopeGenerator(config,
|
||||
infrastructureOptions: opt =>
|
||||
{
|
||||
var logger = provider.GetRequiredService<ILogger<EGDbContext>>();
|
||||
options.UseSqlServer(connStr)
|
||||
.LogTo(log => logger.LogInformation("{log}", log), Microsoft.Extensions.Logging.LogLevel.Trace)
|
||||
.EnableSensitiveDataLogging()
|
||||
.EnableDetailedErrors();
|
||||
opt.AddDbTriggerParams(config);
|
||||
opt.AddDbContext((provider, options) =>
|
||||
{
|
||||
var logger = provider.GetRequiredService<ILogger<EGDbContext>>();
|
||||
options.UseSqlServer(connStr)
|
||||
.LogTo(log => logger.LogInformation("{log}", log), Microsoft.Extensions.Logging.LogLevel.Trace)
|
||||
.EnableSensitiveDataLogging()
|
||||
.EnableDetailedErrors();
|
||||
});
|
||||
},
|
||||
options: opt =>
|
||||
{
|
||||
opt.SqlCacheOptions = new()
|
||||
{
|
||||
ConnectionString = connStr,
|
||||
SchemaName = "dbo",
|
||||
TableName = "TBDD_CACHE"
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
builder.Services.Configure<CookiePolicyOptions>(options =>
|
||||
{
|
||||
@@ -162,18 +162,10 @@ try
|
||||
// Register mail services
|
||||
builder.Services.AddEnvelopeMailService();
|
||||
|
||||
builder.Services.AddDispatcher<EGDbContext>();
|
||||
|
||||
builder.Services.AddMemoryCache();
|
||||
|
||||
builder.ConfigureBySection<CustomImages>();
|
||||
|
||||
builder.ConfigureBySection<AnnotationParams>();
|
||||
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
builder.Services.AddUserManager<EGDbContext>();
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseMiddleware<ExceptionHandlingMiddleware>();
|
||||
|
||||
Reference in New Issue
Block a user