1414using Microsoft . AspNetCore . Mvc ;
1515using Swashbuckle . AspNetCore . Swagger ;
1616using System . Reflection ;
17+ using Microsoft . Extensions . Hosting ;
1718
1819namespace AspNetCoreLocalization
1920{
2021 public class Startup
2122 {
2223 private bool _createNewRecordWhenLocalisedStringDoesNotExist = false ;
23- public Startup ( IHostingEnvironment env )
24+ public Startup ( IConfiguration configuration , IWebHostEnvironment env )
2425 {
25- var builder = new ConfigurationBuilder ( )
26- . SetBasePath ( env . ContentRootPath )
27- . AddJsonFile ( "appsettings.json" , optional : true , reloadOnChange : true )
28- . AddJsonFile ( $ "appsettings.{ env . EnvironmentName } .json", optional : true ) ;
29-
30- builder . AddEnvironmentVariables ( ) ;
31- Configuration = builder . Build ( ) ;
26+ Configuration = configuration ;
3227
3328 if ( env . IsDevelopment ( ) )
3429 {
3530 _createNewRecordWhenLocalisedStringDoesNotExist = true ;
3631 }
3732 }
3833
39- public IConfigurationRoot Configuration { get ; set ; }
34+ public IConfiguration Configuration { get ; }
4035
4136 public void ConfigureServices ( IServiceCollection services )
4237 {
@@ -85,7 +80,9 @@ public void ConfigureServices(IServiceCollection services)
8580 options . SupportedUICultures = supportedCultures ;
8681 } ) ;
8782
88- services . AddMvc ( ) . SetCompatibilityVersion ( CompatibilityVersion . Version_2_2 )
83+ services . AddControllersWithViews ( )
84+ . AddNewtonsoftJson ( )
85+ . SetCompatibilityVersion ( CompatibilityVersion . Version_3_0 )
8986 . AddViewLocalization ( )
9087 . AddDataAnnotationsLocalization ( options =>
9188 {
@@ -106,21 +103,23 @@ public void ConfigureServices(IServiceCollection services)
106103 } ) ;
107104 }
108105
109- public void Configure ( IApplicationBuilder app , IHostingEnvironment env )
106+ public void Configure ( IApplicationBuilder app , IWebHostEnvironment env )
110107 {
111108 var locOptions = app . ApplicationServices . GetService < IOptions < RequestLocalizationOptions > > ( ) ;
112109 app . UseRequestLocalization ( locOptions . Value ) ;
113110
111+ app . UseDefaultFiles ( ) ;
114112 app . UseStaticFiles ( ) ;
115113
116- app . UseMvc ( routes =>
114+ app . UseRouting ( ) ;
115+
116+ app . UseEndpoints ( endpoints =>
117117 {
118- routes . MapRoute (
118+ endpoints . MapControllerRoute (
119119 name : "default" ,
120- template : "{controller=Home}/{action=Index}/{id?}" ) ;
120+ pattern : "{controller=Home}/{action=Index}/{id?}" ) ;
121121 } ) ;
122122
123- // Enable middleware to serve generated Swagger as a JSON endpoint.
124123 app . UseSwagger ( ) ;
125124 app . UseSwaggerUI ( c =>
126125 {
0 commit comments