fengling-console/Program.cs
movingsam ca491924ae feat: 添加 CPM 中央包管理和 CI/CD 配置
- 添加 global.json 统一 .NET SDK 版本 (10.0.103)
- 添加 Directory.Build.props 和 Directory.Packages.props 中央包管理
- 添加 NuGet.Config 包源映射 (gitea + nuget.org)
- 添加 CI 工作流: build.yml (编译), docker.yml (构建镜像), deploy.yml (K8s 部署)
- 添加 k8s/ 目录: deployment.yaml, service.yaml
- 修复项目引用路径
- 升级 Swashbuckle 7.1.0 + Microsoft.OpenApi 1.6.28 解决 .NET 10 兼容性
2026-02-28 14:05:38 +08:00

108 lines
3.2 KiB
C#

using System.Reflection;
using Fengling.Console.Services;
using Fengling.Platform.Domain.AggregatesModel.UserAggregate;
using Fengling.Platform.Domain.AggregatesModel.RoleAggregate;
using Fengling.Platform.Infrastructure;
using OpenIddict.Abstractions;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Identity;
using Microsoft.IdentityModel.Tokens;
using System.Text;
using NetCorePal.Extensions.DependencyInjection;
using OpenIddict.Validation.AspNetCore;
using YarpGateway.Data;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
// Use PlatformDbContext for all identity
builder.Services.AddDbContext<PlatformDbContext>(options =>
{
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"));
if (builder.Environment.IsDevelopment())
{
options.EnableSensitiveDataLogging();
}
options.EnableDetailedErrors();
});
builder.Services.AddDbContext<GatewayDbContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("GatewayConnection")));
// Use Platform's identity
builder.Services.AddIdentity<ApplicationUser, ApplicationRole>()
.AddEntityFrameworkStores<PlatformDbContext>()
.AddDefaultTokenProviders();
builder.Services.AddHttpContextAccessor();
builder.Services.AddHttpClient();
builder.Services.AddScoped<IOAuthClientService, OAuthClientService>();
// Register Platform managers
builder.Services.AddScoped<ITenantStore, TenantStore<PlatformDbContext>>();
builder.Services.AddScoped<ITenantManager, TenantManager>();
builder.Services.AddScoped<IUserService, UserService>();
builder.Services.AddScoped<ITenantService, TenantService>();
builder.Services.AddScoped<IRoleService, RoleService>();
builder.Services.AddScoped<IGatewayService, GatewayService>();
builder.Services.AddScoped<IH5LinkService, H5LinkService>();
builder.Services.AddOpenIddict()
.AddCore(options => { options.UseEntityFrameworkCore().UseDbContext<PlatformDbContext>(); })
.AddValidation(options =>
{
options.SetIssuer("http://localhost:5132/");
options.UseIntrospection()
.SetClientId("fengling-api")
.SetClientSecret("fengling-api-secret");
options.UseSystemNetHttp();
options.UseAspNetCore();
});
builder.Services.AddAuthentication(options =>
{
options.DefaultScheme = OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme;
});
builder.Services.AddAuthorization();
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAll", policy =>
{
policy.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new() { Title = "Fengling.Console API", Version = "v1" });
c.CustomSchemaIds(type => type.FullName);
});
builder.Services.AddRepositories(typeof(PlatformDbContext).Assembly);
var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Fengling.Console API V1"); });
app.UseCors("AllowAll");
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();