|
|
using Ds.WMS.WebCore;
|
|
|
using Microsoft.OpenApi.Models;
|
|
|
using System.Reflection;
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args).UseMyConfiguration();
|
|
|
|
|
|
|
|
|
// 使用动态启动类 必须集成 webcore 即可实现配置文件的介绍
|
|
|
|
|
|
|
|
|
|
|
|
// Add services to the container.
|
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
|
|
|
|
builder.Services.AddControllers(options =>
|
|
|
{
|
|
|
options.Filters.Add(new DsAppActionFilter());
|
|
|
});
|
|
|
// 使用扩展方法来加载其他 Startup 类
|
|
|
|
|
|
builder.Services.AddSwaggerGen(c =>
|
|
|
{
|
|
|
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
|
|
|
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
|
|
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
|
|
c.IncludeXmlComments(xmlPath);
|
|
|
});
|
|
|
|
|
|
builder.UseDynamicStartups();
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
app.UseMiddleware<RequestLoggingMiddleware>();
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
//if (app.Environment.IsDevelopment())
|
|
|
//{
|
|
|
// app.UseSwagger();
|
|
|
// app.UseSwaggerUI();
|
|
|
//}
|
|
|
// 启用中间件服务生成 Swagger 作为 JSON 终结点
|
|
|
app.UseSwagger();
|
|
|
|
|
|
|
|
|
// 启用中间件服务对 swagger-ui,指定 Swagger JSON 终结点
|
|
|
app.UseSwaggerUI(c =>
|
|
|
{
|
|
|
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
|
|
|
});
|
|
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
|
app.UseRouting();
|
|
|
app.UseEndpoints(endpoints =>
|
|
|
{
|
|
|
endpoints.MapControllers();
|
|
|
});
|
|
|
|
|
|
// 顺序放在最后即可
|
|
|
app.UseDynamicStartups();
|
|
|
app.Run();
|
|
|
|