using DataVApi.Order; using DataVAPI.AppConfig; using DataVAPI.ConfigureSwagger; using DataVAPI.Model; using DataVAPI.ModelDataBus; using DataVAPI.Tool.IOT; using DataVAPI.Tool.控制台显示; using DataVAPI.UpAndDown; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; namespace DataVAPI { public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; ConsoleHelper.WriteSuccessLine("接口已完成初始化."); AppConfigurtaionServices appConfigurtaionServices = new AppConfigurtaionServices(); } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. // 配置依赖注入以在运行时根据依赖关系创建对象 public void ConfigureServices(IServiceCollection services) { SugarDb.Conn = Configuration["DbConnectionstring"].ToString(); DataBus.connStr = Configuration["mongoDB.connStr"].ToString(); DataBus.dbName = Configuration["mongoDB.dbName"].ToString(); DataBus.DeviceSecret = Configuration["DeviceSecret"].ToString(); DataBus.DeviceName = Configuration["DeviceName"].ToString(); DataBus.ProductKey = Configuration["ProductKey"].ToString(); ProcessServer.Instance.Initialize(); //注册swagger服务 services.AddSwaggerUp(); services.AddControllers(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // 配置中间件(middleware)以构建请求处理流水线。 public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseStaticFiles(); //添加swagger相关的中间件 app.UseSwagger(); //配置Cors app.UseCors("any"); app.UseSwaggerUI(c => { c.InjectJavascript($"/swagger/ui/zh_CN.js"); // 加载中文包 c.SwaggerEndpoint($"/swagger/V1/swagger.json", "服务API V1"); //路径配置,设置为空 表示直接在根域名(localhost:5000)访问 swagger-ui //注意 localhost:8088/swagger 是访问补发哦的,去launcnSetting.json 把 launchUrl 去掉 //如果你想换一个路径 直接写名字即可,比如 c.RoutePrefix = "doc"; c.RoutePrefix = "";//添加一层路径 }); app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); } } }