using Microsoft.OpenApi.Models; using SlnMesnac.Common; using SlnMesnac.Config; using SlnMesnac.Plc; using SlnMesnac.Quartz; using SlnMesnac.Repository; using SlnMesnac.Serilog; using SlnMesnac.Mqtt; using SlnMesnac.TouchSocket; using System.Runtime.Serialization; 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(); }); //注册通用类 services.AddCommonSetup(); //注册ORM services.AddSqlSugarSetup(); //注册Service services.AddServices(); //注册Quartz //services.AddQuartzSetUp(); //注册PLC services.AddPlcSetup(); //注册MQTT //services.AddMqttSetup(); //注册TouchSocket //services.AddTouchSocketSetup(); } /// /// 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(); //初始化PLC中间件 app.UsePlcExtensions(); //app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); } } }