diff --git a/Fengling.Console.csproj b/Fengling.Console.csproj
index 7c9e56e..c839a9f 100644
--- a/Fengling.Console.csproj
+++ b/Fengling.Console.csproj
@@ -19,6 +19,8 @@
+
+
diff --git a/Program.cs b/Program.cs
index 5b5bb21..65f3c7a 100644
--- a/Program.cs
+++ b/Program.cs
@@ -11,6 +11,7 @@ using System.Text;
using Fengling.Console.Datas;
using Fengling.Console.Models.Entities;
using Fengling.Platform.Infrastructure;
+using NetCorePal.Extensions.DependencyInjection;
using OpenIddict.Validation.AspNetCore;
using YarpGateway.Data;
@@ -48,10 +49,7 @@ builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddOpenIddict()
- .AddCore(options =>
- {
- options.UseEntityFrameworkCore().UseDbContext();
- })
+ .AddCore(options => { options.UseEntityFrameworkCore().UseDbContext(); })
.AddValidation(options =>
{
options.SetIssuer("http://localhost:5132/");
@@ -77,8 +75,8 @@ builder.Services.AddCors(options =>
options.AddPolicy("AllowAll", policy =>
{
policy.AllowAnyOrigin()
- .AllowAnyMethod()
- .AllowAnyHeader();
+ .AllowAnyMethod()
+ .AllowAnyHeader();
});
});
@@ -95,13 +93,37 @@ builder.Services.AddSwaggerGen(c =>
}
});
+
+builder.Services.AddRepositories(typeof(ApplicationDbContext).Assembly,typeof(PlatformDbContext).Assembly);
+
+builder.Services.AddDbContext(options =>
+{
+ options.UseNpgsql(builder.Configuration.GetConnectionString("PostgreSQL"));
+ // 仅在开发环境启用敏感数据日志,防止生产环境泄露敏感信息
+ if (builder.Environment.IsDevelopment())
+ {
+ options.EnableSensitiveDataLogging();
+ }
+
+ options.EnableDetailedErrors();
+});
+builder.Services.AddUnitOfWork();
+builder.Services.AddRedisLocks();
+
+builder.Services.AddMediatR(cfg =>
+ cfg.RegisterServicesFromAssemblies(
+ Assembly.GetExecutingAssembly(),
+ typeof(PlatformDbContext).Assembly
+ )
+ .AddCommandLockBehavior()
+ .AddKnownExceptionValidationBehavior()
+ .AddUnitOfWorkBehaviors());
+
+
var app = builder.Build();
app.UseSwagger();
-app.UseSwaggerUI(c =>
-{
- c.SwaggerEndpoint("/swagger/v1/swagger.json", "Fengling.Console API V1");
-});
+app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Fengling.Console API V1"); });
app.UseCors("AllowAll");
@@ -110,4 +132,4 @@ app.UseAuthorization();
app.MapControllers();
-app.Run();
+app.Run();
\ No newline at end of file