using Microsoft.OpenApi.Models; using SlnMesnac.Config; using SlnMesnac.Quartz; using SlnMesnac.Serilog; using SlnMesnac.Extensions; using System.Runtime.Serialization; using SlnMesnac.Business.Airport; namespace SlnMesnac { /// /// /// public class Startup { /// /// /// /// public Startup(IConfiguration configuration) { Configuration = configuration; } /// /// /// public IConfiguration Configuration { get; } /// /// This method gets called by the runtime. Use this method to add services to the container. /// /// [Obsolete] public void ConfigureServices(IServiceCollection services) { services.AddControllers(); //配置Swagger services.AddSwaggerGen(swagger => { //自定义接口信息 swagger.SwaggerDoc("V1.0", new OpenApiInfo { Title = "MES Web Api", Version = "V1.0", Description = $"API版本V1.0", Contact = new OpenApiContact { Name = "MES Web Api", Email = "wenjy@mesnac.com" } }); //自定义实体别名 swagger.CustomSchemaIds(type => type.GetCustomAttributes(typeof(DataContractAttribute), true) .Cast() .FirstOrDefault()?.Name); //配置Action名称 var path = Path.Combine(AppContext.BaseDirectory, "SlnMesnac.xml"); swagger.IncludeXmlComments(path, true); // true : 显示控制器层注释 swagger.OrderActionsBy(o => o.RelativePath); // 对action的名称进行排序,如果有多个,就可以看见效果了。 }); //注册配置类 services.AddSingleton(provider => { var configuration = provider.GetService(); return configuration.GetSection("AppConfig").Get(); }); //注册SqlSugar services.AddSqlSugarSetup(); //注册服务 //services.AddServices(); //注册任务调度 services.AddQuartzSetUp(); //添加服务 //services.AddHostedService(); } /// /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. /// /// /// public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } //启用Swagger中间件 app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/V1.0/swagger.json", "MES Web Api V1.0"); c.RoutePrefix = ""; }); //启用Serilog中间件 app.UseSerilogExtensions(); //app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); } } }