Add distributed cache, localization, and infra services
- Add DigitalData.Core.API and SQL Server distributed cache dependencies - Register EnvelopeGenerator.Application project reference - Configure distributed SQL Server cache and memory cache - Register infrastructure, application, and user management services - Set up EF Core with SQL Server and detailed logging - Enable localization with configurable supported cultures - Improve modularity and extensibility of service registration
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DigitalData.Core.API" Version="2.2.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||
<PackageReference Include="GdPicture" Version="14.3.3" />
|
||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.1.4" />
|
||||
@@ -19,9 +20,11 @@
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.16" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
|
||||
<PackageReference Include="DevExpress.Reporting.Core" Version="24.2.*" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.SqlServer" Version="8.0.17" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\EnvelopeGenerator.Application\EnvelopeGenerator.Application.csproj" />
|
||||
<ProjectReference Include="..\EnvelopeGenerator.Domain\EnvelopeGenerator.Domain.csproj" />
|
||||
<ProjectReference Include="..\EnvelopeGenerator.Infrastructure\EnvelopeGenerator.Infrastructure.csproj" />
|
||||
<ProjectReference Include="..\EnvelopeGenerator.PdfEditor\EnvelopeGenerator.PdfEditor.csproj" />
|
||||
|
||||
@@ -1,15 +1,51 @@
|
||||
using DigitalData.UserManager.DependencyInjection;
|
||||
using EnvelopeGenerator.Application;
|
||||
using EnvelopeGenerator.Infrastructure;
|
||||
using EnvelopeGenerator.ServiceHost;
|
||||
using EnvelopeGenerator.ServiceHost.Extensions;
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Globalization;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddFinalizeDocumentJob(builder.Configuration);
|
||||
builder.Services.AddHostedService<Worker>();
|
||||
var config = builder.Configuration;
|
||||
var connStr = config.GetConnectionString("Default") ??
|
||||
throw new InvalidOperationException("Connection string 'Default' is missing in the configuration.");
|
||||
|
||||
#region Service configuration
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddHostedService<Worker>();
|
||||
builder.Services.AddDistributedSqlServerCache(options =>
|
||||
{
|
||||
options.ConnectionString = connStr;
|
||||
options.SchemaName = "dbo";
|
||||
options.TableName = "TBDD_CACHE";
|
||||
});
|
||||
#pragma warning disable CS0618
|
||||
builder.Services.AddFinalizeDocumentJob(config);
|
||||
builder.Services.AddEnvelopeGeneratorInfrastructureServices(
|
||||
opt =>
|
||||
{
|
||||
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();
|
||||
});
|
||||
});
|
||||
builder.Services.AddEnvelopeGeneratorServices(config);
|
||||
builder.Services.AddMemoryCache();
|
||||
builder.Services.AddUserManager<EGDbContext>();
|
||||
#pragma warning restore CS0618
|
||||
builder.Services.AddLocalization();
|
||||
#endregion
|
||||
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
@@ -22,6 +58,18 @@ if (app.Environment.IsDevelopment())
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
#region Localizer
|
||||
var supportedCultureNames = config.GetSection("SupportedCultures").Get<string[]>() ?? ["de-DE", "en-US"];
|
||||
var supportedCultures = supportedCultureNames.Select(cName => new CultureInfo(cName)).ToList();
|
||||
var requestLocalizationOptions = new RequestLocalizationOptions
|
||||
{
|
||||
SupportedCultures = supportedCultures,
|
||||
SupportedUICultures = supportedCultures
|
||||
};
|
||||
requestLocalizationOptions.RequestCultureProviders.Add(new QueryStringRequestCultureProvider());
|
||||
app.UseRequestLocalization(requestLocalizationOptions);
|
||||
#endregion
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
Reference in New Issue
Block a user