Files
StoreWeb/Store.API/Program.cs
T

73 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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(实现见 StoreHub.Framework)
builder.Services.AddStoreHub();
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();
#region DB
#endregion
var app = builder.Build();
// 初始化 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();
}
}