refactor(Finalizer.Program): simplify EnvelopeGenerator service registration using AddEnvelopeGenerator extension
- Replaced manual service setup with AddEnvelopeGenerator fluent configuration - Added EnvelopeGenerator.DependencyInjection namespace - Integrated distributed SQL Server cache for EG services - Improved DI structure and reduced obsolete warnings
This commit is contained in:
parent
3bc5439b5a
commit
568f43186c
@ -38,6 +38,7 @@ public static class DependencyInjection
|
|||||||
_serviceRegs.Dequeue().Invoke(services);
|
_serviceRegs.Dequeue().Invoke(services);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: update to use attributes and reflections instead of _addingStatus-dictionary
|
||||||
private readonly Dictionary<string, bool> _addingStatus = new ()
|
private readonly Dictionary<string, bool> _addingStatus = new ()
|
||||||
{
|
{
|
||||||
{ nameof(AddLocalization), false },
|
{ nameof(AddLocalization), false },
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\EnvelopeGenerator.Application\EnvelopeGenerator.Application.csproj" />
|
<ProjectReference Include="..\EnvelopeGenerator.Application\EnvelopeGenerator.Application.csproj" />
|
||||||
|
<ProjectReference Include="..\EnvelopeGenerator.DependencyInjection\EnvelopeGenerator.DependencyInjection.csproj" />
|
||||||
<ProjectReference Include="..\EnvelopeGenerator.Infrastructure\EnvelopeGenerator.Infrastructure.csproj" />
|
<ProjectReference Include="..\EnvelopeGenerator.Infrastructure\EnvelopeGenerator.Infrastructure.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
using EnvelopeGenerator.Application;
|
using EnvelopeGenerator.DependencyInjection;
|
||||||
using EnvelopeGenerator.Finalizer;
|
using EnvelopeGenerator.Finalizer;
|
||||||
using EnvelopeGenerator.Infrastructure;
|
using EnvelopeGenerator.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@ -27,25 +27,28 @@ try
|
|||||||
var connStr = config.GetConnectionString(cnnStrName)
|
var connStr = config.GetConnectionString(cnnStrName)
|
||||||
?? throw new InvalidOperationException($"Connection string '{cnnStrName}' is missing in the application configuration.");
|
?? throw new InvalidOperationException($"Connection string '{cnnStrName}' is missing in the application configuration.");
|
||||||
|
|
||||||
#pragma warning disable CS0618 // Type or member is obsolete
|
builder.Services.AddEnvelopeGenerator(egOptions => egOptions
|
||||||
builder.Services.AddEGInfrastructureServices(
|
.AddLocalization()
|
||||||
opt =>
|
.AddDistributedSqlServerCache(options =>
|
||||||
|
{
|
||||||
|
options.ConnectionString = connStr;
|
||||||
|
options.SchemaName = "dbo";
|
||||||
|
options.TableName = "TBDD_CACHE";
|
||||||
|
})
|
||||||
|
.AddInfrastructure(opt =>
|
||||||
{
|
{
|
||||||
opt.AddDbTriggerParams(config);
|
opt.AddDbTriggerParams(config);
|
||||||
opt.AddDbContext((provider, options) =>
|
opt.AddDbContext((provider, options) =>
|
||||||
{
|
{
|
||||||
var logger = provider.GetRequiredService<ILogger<EGDbContext>>();
|
var logger = provider.GetRequiredService<ILogger<EGDbContext>>();
|
||||||
options.UseSqlServer(connStr)
|
options.UseSqlServer(connStr)
|
||||||
.LogTo(log => logger.LogInformation("{log}", log), Microsoft.Extensions.Logging.LogLevel.Trace)
|
.LogTo(log => logger.LogInformation("{log}", log), LogLevel.Trace)
|
||||||
.EnableSensitiveDataLogging()
|
.EnableSensitiveDataLogging()
|
||||||
.EnableDetailedErrors();
|
.EnableDetailedErrors();
|
||||||
});
|
});
|
||||||
});
|
})
|
||||||
#pragma warning restore CS0618 // Type or member is obsolete
|
.AddServices(config)
|
||||||
|
);
|
||||||
#pragma warning disable CS0618 // Type or member is obsolete
|
|
||||||
builder.Services.AddEnvelopeGeneratorServices(config);
|
|
||||||
#pragma warning restore CS0618 // Type or member is obsolete
|
|
||||||
#endregion Add DB Context, EG Inf. and Services
|
#endregion Add DB Context, EG Inf. and Services
|
||||||
|
|
||||||
var host = builder.Build();
|
var host = builder.Build();
|
||||||
|
|||||||
@ -105,6 +105,7 @@ try
|
|||||||
});
|
});
|
||||||
builder.Services.AddOpenApi();
|
builder.Services.AddOpenApi();
|
||||||
|
|
||||||
|
// TODO: Update to configure with EnvelopeGenerator.DependencyInjection
|
||||||
//AddEF Core dbcontext
|
//AddEF Core dbcontext
|
||||||
var useDbMigration = Environment.GetEnvironmentVariable("MIGRATION_TEST_MODE") == true.ToString() || config.GetValue<bool>("UseDbMigration");
|
var useDbMigration = Environment.GetEnvironmentVariable("MIGRATION_TEST_MODE") == true.ToString() || config.GetValue<bool>("UseDbMigration");
|
||||||
var cnnStrName = useDbMigration ? "DbMigrationTest" : "Default";
|
var cnnStrName = useDbMigration ? "DbMigrationTest" : "Default";
|
||||||
|
|||||||
@ -86,6 +86,7 @@ try
|
|||||||
builder.Services.AddSwaggerGen();
|
builder.Services.AddSwaggerGen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Update to configure with EnvelopeGenerator.DependencyInjection
|
||||||
//AddEF Core dbcontext
|
//AddEF Core dbcontext
|
||||||
var useDbMigration = Environment.GetEnvironmentVariable("MIGRATION_TEST_MODE") == true.ToString() || config.GetValue<bool>("UseDbMigration");
|
var useDbMigration = Environment.GetEnvironmentVariable("MIGRATION_TEST_MODE") == true.ToString() || config.GetValue<bool>("UseDbMigration");
|
||||||
var cnnStrName = useDbMigration ? "DbMigrationTest" : "Default";
|
var cnnStrName = useDbMigration ? "DbMigrationTest" : "Default";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user