71 lines
2.2 KiB
C#
71 lines
2.2 KiB
C#
using Asp.Versioning;
|
|
using MAX.Framework.DependencyInjection;
|
|
using Scalar.AspNetCore;
|
|
|
|
public partial class Program
|
|
{
|
|
private static void Main(string[] args)
|
|
{
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// IOC 注册:自动注册 ISingletonDependency / IScopedDependency / ITransientDependency,并执行所有 IStartup / IModule.AddModule
|
|
// 模块服务注册阶段(等价于 builder.Services.AddStoreHub(builder.Configuration, builder.Environment),额外把配置/环境交给模块)
|
|
builder.AddStore();
|
|
builder.Services.AddFreeSqlDB();
|
|
// JWT 验证:注册 JwtBearer 认证 + 令牌服务 + OpenAPI Bearer 安全方案(配置节 Jwt)
|
|
builder.Services.AddStoreHubJwt(builder.Configuration);
|
|
// Add services to the container.
|
|
|
|
//builder.Services.Configure<Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions>(options =>
|
|
//{
|
|
// // 兼容迁移的同步控制器:允许同步读写请求/响应 IO(旧 asmx 行为)
|
|
// options.AllowSynchronousIO = true;
|
|
//});
|
|
builder.Services.AddControllers();
|
|
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
|
builder.Services.AddApiVersioning(options =>
|
|
{
|
|
options.DefaultApiVersion = new ApiVersion(1, 0);
|
|
options.ReportApiVersions = true;
|
|
options.ApiVersionReader = new UrlSegmentApiVersionReader();
|
|
}).AddMvc().AddApiExplorer(options =>
|
|
{
|
|
options.GroupNameFormat = "'v'V";
|
|
options.SubstituteApiVersionInUrl = true;
|
|
}).AddOpenApi();
|
|
|
|
|
|
WebApplication app = builder.Build();
|
|
|
|
app.UseStore();
|
|
// 初始化 KJD 迁移的静态提供者(MysqlUtils 连接提供 / 业务配置读取)
|
|
//StoreHub.KJDWebService.Commons.AdoProvider.SetServiceProvider(app.Services);
|
|
//StoreHub.KJDWebService.Commons.KJDConfig.SetConfiguration(app.Configuration);
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.MapOpenApi().WithDocumentPerVersion();
|
|
app.MapScalarApiReference(options =>
|
|
{
|
|
|
|
options.Title = "商铺管理API V1";
|
|
options.AddDocuments(new[] { "v1", "v2" });
|
|
});
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseAuthentication();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
|
|
app.Run();
|
|
}
|
|
}
|
|
|
|
|
|
|