Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

82 рядки
3.0 KiB

  1. using DataVApi.Order;
  2. using DataVAPI.AppConfig;
  3. using DataVAPI.ConfigureSwagger;
  4. using DataVAPI.Model;
  5. using DataVAPI.ModelDataBus;
  6. using DataVAPI.Tool.IOT;
  7. using DataVAPI.Tool.控制台显示;
  8. using DataVAPI.UpAndDown;
  9. using Microsoft.AspNetCore.Builder;
  10. using Microsoft.AspNetCore.Hosting;
  11. using Microsoft.Extensions.Configuration;
  12. using Microsoft.Extensions.DependencyInjection;
  13. using Microsoft.Extensions.Hosting;
  14. namespace DataVAPI
  15. {
  16. public class Startup
  17. {
  18. public Startup(IConfiguration configuration)
  19. {
  20. Configuration = configuration;
  21. ConsoleHelper.WriteSuccessLine("接口已完成初始化.");
  22. AppConfigurtaionServices appConfigurtaionServices = new AppConfigurtaionServices();
  23. }
  24. public IConfiguration Configuration { get; }
  25. // This method gets called by the runtime. Use this method to add services to the container.
  26. // 配置依赖注入以在运行时根据依赖关系创建对象
  27. public void ConfigureServices(IServiceCollection services)
  28. {
  29. SugarDb.Conn = Configuration["DbConnectionstring"].ToString();
  30. DataBus.connStr = Configuration["mongoDB.connStr"].ToString();
  31. DataBus.dbName = Configuration["mongoDB.dbName"].ToString();
  32. DataBus.DeviceSecret = Configuration["DeviceSecret"].ToString();
  33. DataBus.DeviceName = Configuration["DeviceName"].ToString();
  34. DataBus.ProductKey = Configuration["ProductKey"].ToString();
  35. ProcessServer.Instance.Initialize();
  36. //注册swagger服务
  37. services.AddSwaggerUp();
  38. services.AddControllers();
  39. }
  40. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  41. // 配置中间件(middleware)以构建请求处理流水线。
  42. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  43. {
  44. if (env.IsDevelopment())
  45. {
  46. app.UseDeveloperExceptionPage();
  47. }
  48. app.UseStaticFiles();
  49. //添加swagger相关的中间件
  50. app.UseSwagger();
  51. //配置Cors
  52. app.UseCors("any");
  53. app.UseSwaggerUI(c =>
  54. {
  55. c.InjectJavascript($"/swagger/ui/zh_CN.js"); // 加载中文包
  56. c.SwaggerEndpoint($"/swagger/V1/swagger.json", "服务API V1");
  57. //路径配置,设置为空 表示直接在根域名(localhost:5000)访问 swagger-ui
  58. //注意 localhost:8088/swagger 是访问补发哦的,去launcnSetting.json 把 launchUrl 去掉
  59. //如果你想换一个路径 直接写名字即可,比如 c.RoutePrefix = "doc";
  60. c.RoutePrefix = "";//添加一层路径
  61. });
  62. app.UseHttpsRedirection();
  63. app.UseRouting();
  64. app.UseAuthorization();
  65. app.UseEndpoints(endpoints =>
  66. {
  67. endpoints.MapControllers();
  68. });
  69. }
  70. }
  71. }