62 lines
1.5 KiB
C#
62 lines
1.5 KiB
C#
using Asp.Versioning;
|
||
using Scalar.AspNetCore;
|
||
using StoreHub.Framework.DependencyInjection;
|
||
|
||
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.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();
|
||
|
||
// 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();
|
||
}
|
||
} |