Startup.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Microsoft.AspNetCore.Builder;
  2. using Microsoft.AspNetCore.Hosting;
  3. using Microsoft.Extensions.Configuration;
  4. using Microsoft.Extensions.DependencyInjection;
  5. using Microsoft.Extensions.Hosting;
  6. using Microsoft.Extensions.Options;
  7. using Microsoft.OpenApi.Models;
  8. using System.Reflection;
  9. namespace ServiceCenter.WebApi
  10. {
  11. public class Startup
  12. {
  13. public Startup(IConfiguration configuration)
  14. {
  15. Configuration = configuration;
  16. }
  17. public IConfiguration Configuration { get; }
  18. // This method gets called by the runtime. Use this method to add services to the container.
  19. public void ConfigureServices(IServiceCollection services)
  20. {
  21. services.AddControllers();
  22. services.AddSwaggerGen(c =>
  23. {
  24. //c.SwaggerDoc("v1", new OpenApiInfo { Title = "WCSAPI", Version = "v1" });
  25. c.SwaggerDoc("v1", new OpenApiInfo
  26. {
  27. Version = "v1",
  28. Title = "WCSAPI",
  29. Description = "API描述"
  30. });
  31. var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
  32. c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
  33. });
  34. }
  35. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  36. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  37. {
  38. if (env.IsDevelopment())
  39. {
  40. app.UseDeveloperExceptionPage();
  41. app.UseSwagger();
  42. app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebApplication1 v1"));
  43. //http://localhost:8080/swagger/index.html
  44. }
  45. app.UseHttpsRedirection();
  46. app.UseRouting();
  47. app.UseAuthorization();
  48. app.UseEndpoints(endpoints =>
  49. {
  50. endpoints.MapControllers();
  51. });
  52. }
  53. }
  54. }