55
66 using Microsoft . AspNetCore . Builder ;
77 using Microsoft . AspNetCore . Hosting ;
8+ using Microsoft . Extensions . Configuration ;
89 using Microsoft . Extensions . DependencyInjection ;
910 using Microsoft . Extensions . Logging ;
1011 using Microsoft . Extensions . PlatformAbstractions ;
1920 /// Start class of the API.
2021 /// </summary>
2122 public class Startup {
23+ /// <summary>
24+ /// Constructor.
25+ /// </summary>
26+ /// <param name="env"></param>
27+ public Startup ( IHostingEnvironment env ) {
28+ var builder =
29+ new ConfigurationBuilder ( ) . SetBasePath ( env . ContentRootPath )
30+ . AddJsonFile ( "appsettings.json" )
31+ . AddEnvironmentVariables ( ) ;
32+
33+ this . Configuration = builder . Build ( ) ;
34+ }
35+
36+ /// <summary>
37+ /// App config.
38+ /// </summary>
39+ private IConfiguration Configuration {
40+ get ;
41+ }
42+
2243 /// <summary>
2344 /// This method gets called by the runtime. Use this method to add services to the container.
2445 /// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
@@ -30,10 +51,9 @@ public void ConfigureServices(IServiceCollection services) {
3051
3152 // Inject an implementation of ISwaggerProvider with defaulted settings applied
3253 services . AddSwaggerGen ( ) ;
33-
3454 services . ConfigureSwaggerGen (
3555 options => {
36- options . SingleApiVersion ( CreateSwaggerInfo ( ) ) ;
56+ options . SingleApiVersion ( this . CreateSwaggerInfo ( ) ) ;
3757
3858 // Determine base path for the application.
3959 string basePath = PlatformServices . Default . Application . ApplicationBasePath ;
@@ -54,6 +74,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
5474 loggerFactory . AddConsole ( ) ;
5575
5676 if ( env . IsDevelopment ( ) ) {
77+ // Show info about an exception if one occurs only in development environment
5778 app . UseDeveloperExceptionPage ( ) ;
5879 }
5980
@@ -65,10 +86,8 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
6586
6687 InitMapper ( ) ;
6788
68- // Enable middleware to serve generated Swagger as a JSON endpoint
89+ // Enable middleware to use swagger ui
6990 app . UseSwagger ( ) ;
70-
71- // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.)
7291 app . UseSwaggerUi ( ) ;
7392 }
7493
@@ -87,16 +106,15 @@ private static void InitMapper() {
87106 } ) ;
88107 }
89108
90- private static Info CreateSwaggerInfo ( ) {
109+ private Info CreateSwaggerInfo ( ) {
91110 return new Info {
92- Version = "v1" ,
93- Title = "ASP.NET Core v1.0 API" ,
94- Description = "This is an example of a REST API with ASP.NET Core v1.0" ,
95- TermsOfService = "None" ,
111+ Version = this . Configuration [ "version" ] ,
112+ Title = this . Configuration [ "title" ] ,
113+ Description = this . Configuration [ "description" ] ,
96114 Contact = new Contact {
97- Name = "Jennifer Deigendesch" ,
98- 99- Url = "https://github.com/doubleSlashde/ASPNETCoreExample"
115+ Name = this . Configuration [ "contact-name" ] ,
116+ Email = this . Configuration [ "contact-email" ] ,
117+ Url = this . Configuration [ "contact-url" ]
100118 }
101119 } ;
102120 }
0 commit comments