You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

77 lines
2.8 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. ProcessServer.Instance.Initialize();
  33. //注册swagger服务
  34. services.AddSwaggerUp();
  35. services.AddControllers();
  36. }
  37. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  38. // 配置中间件(middleware)以构建请求处理流水线。
  39. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  40. {
  41. if (env.IsDevelopment())
  42. {
  43. app.UseDeveloperExceptionPage();
  44. }
  45. app.UseStaticFiles();
  46. //添加swagger相关的中间件
  47. app.UseSwagger();
  48. //配置Cors
  49. app.UseCors("any");
  50. app.UseSwaggerUI(c =>
  51. {
  52. c.InjectJavascript($"/swagger/ui/zh_CN.js"); // 加载中文包
  53. c.SwaggerEndpoint($"/swagger/V1/swagger.json", "服务API V1");
  54. //路径配置,设置为空 表示直接在根域名(localhost:5000)访问 swagger-ui
  55. //注意 localhost:8088/swagger 是访问补发哦的,去launcnSetting.json 把 launchUrl 去掉
  56. //如果你想换一个路径 直接写名字即可,比如 c.RoutePrefix = "doc";
  57. c.RoutePrefix = "";//添加一层路径
  58. });
  59. app.UseHttpsRedirection();
  60. app.UseRouting();
  61. app.UseAuthorization();
  62. app.UseEndpoints(endpoints =>
  63. {
  64. endpoints.MapControllers();
  65. });
  66. }
  67. }
  68. }