This commit is contained in:
movingsam 2026-02-19 21:40:22 +08:00
parent d4aff05804
commit 7a9fcf9fc1
2 changed files with 25 additions and 4 deletions

View File

@ -6,6 +6,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="NetCorePal.Extensions.AspNetCore" />
<PackageReference Include="OpenIddict.Quartz" /> <PackageReference Include="OpenIddict.Quartz" />
<PackageReference Include="Swashbuckle.AspNetCore" /> <PackageReference Include="Swashbuckle.AspNetCore" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design">

View File

@ -1,14 +1,18 @@
using System.Reflection;
using Fengling.AuthService.Configuration; using Fengling.AuthService.Configuration;
using Fengling.AuthService.Data; using Fengling.AuthService.Data;
using Fengling.AuthService.Models; using Fengling.AuthService.Models;
using Fengling.Platform.Infrastructure;
using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi; using Microsoft.OpenApi;
using NetCorePal.Extensions.DependencyInjection;
using OpenTelemetry; using OpenTelemetry;
using OpenTelemetry.Resources; using OpenTelemetry.Resources;
using OpenTelemetry.Trace; using OpenTelemetry.Trace;
using Serilog; using Serilog;
using SeedData = Fengling.AuthService.Data.SeedData;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -27,6 +31,14 @@ builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseOpenIddict(); options.UseOpenIddict();
}); });
builder.Services.AddDbContext<PlatformDbContext>(options =>
{
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"));
options.UseOpenIddict();
});
builder.Services.AddRazorPages(); builder.Services.AddRazorPages();
builder.Services.AddControllersWithViews(); builder.Services.AddControllersWithViews();
@ -52,15 +64,23 @@ builder.Services.AddOpenTelemetry()
resource.AddService("Fengling.AuthService")) resource.AddService("Fengling.AuthService"))
.WithTracing(tracing => .WithTracing(tracing =>
tracing.AddAspNetCoreInstrumentation() tracing.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation() .AddHttpClientInstrumentation()
.AddSource("OpenIddict.Server.AspNetCore") .AddSource("OpenIddict.Server.AspNetCore")
.AddOtlpExporter()); .AddOtlpExporter());
builder.Services.AddControllersWithViews(); builder.Services.AddControllersWithViews();
builder.Services.AddHealthChecks() builder.Services.AddHealthChecks()
.AddNpgSql(builder.Configuration.GetConnectionString("DefaultConnection")!); .AddNpgSql(builder.Configuration.GetConnectionString("DefaultConnection")!);
builder.Services.AddRepositories(typeof(ApplicationDbContext).Assembly, typeof(PlatformDbContext).Assembly);
builder.Services.AddMediatR(x => x.RegisterServicesFromAssemblies(typeof(PlatformDbContext).Assembly
, Assembly.GetExecutingAssembly())
.AddCommandLockBehavior()
.AddKnownExceptionValidationBehavior()
.AddUnitOfWorkBehaviors()
);
builder.Services.AddSwaggerGen(options => builder.Services.AddSwaggerGen(options =>
{ {
options.SwaggerDoc("v1", new OpenApiInfo options.SwaggerDoc("v1", new OpenApiInfo
@ -119,4 +139,4 @@ app.MapRazorPages();
app.MapControllers(); app.MapControllers();
app.MapHealthChecks("/health"); app.MapHealthChecks("/health");
app.Run(); app.Run();