Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  2. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
  3. {
  4. loggerFactory.AddConsole(Configuration.GetSection("Logging"));
  5. loggerFactory.AddDebug();
  6.  
  7. app.UseMvc();
  8.  
  9. app.UseSwagger();
  10.  
  11. app.UseSwaggerUI(c =>
  12. {
  13. c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
  14. });
  15.  
  16. }
  17.  
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Linq;
  21. using System.Threading.Tasks;
  22. using Microsoft.AspNetCore.Builder;
  23. using Microsoft.AspNetCore.Hosting;
  24. using Microsoft.Extensions.Configuration;
  25. using Microsoft.Extensions.DependencyInjection;
  26. using Microsoft.Extensions.Logging;
  27. using Swashbuckle.AspNetCore.Swagger;
  28.  
  29. namespace MyFirstWebApi
  30. {
  31. public class Startup
  32. {
  33. public Startup(IHostingEnvironment env)
  34. {
  35. var builder = new ConfigurationBuilder()
  36. .SetBasePath(env.ContentRootPath)
  37. .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
  38. .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
  39. .AddEnvironmentVariables();
  40. Configuration = builder.Build();
  41. }
  42.  
  43. public IConfigurationRoot Configuration { get; }
  44.  
  45. // This method gets called by the runtime. Use this method to add services to the container.
  46. public void ConfigureServices(IServiceCollection services)
  47. {
  48. // Add framework services.
  49. services.AddMvc();
  50.  
  51. //add swagger
  52. services.AddSwaggerGen(c =>
  53. {
  54. c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
  55. });
  56.  
  57. //api explorer
  58. services.AddMvcCore()
  59. .AddApiExplorer();
  60.  
  61. }
  62.  
  63. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  64. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
  65. {
  66. loggerFactory.AddConsole(Configuration.GetSection("Logging"));
  67. loggerFactory.AddDebug();
  68.  
  69. app.UseMvc();
  70.  
  71. app.UseSwagger();
  72.  
  73. app.UseSwaggerUI(c =>
  74. {
  75. c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
  76. });
  77.  
  78. }
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement