11using System ;
22using System . Collections . Generic ;
3+ using System . IO ;
34using System . Linq ;
45using System . Threading . Tasks ;
5- using Microsoft . AspNet . Builder ;
6- using Microsoft . AspNet . Hosting ;
6+ using Microsoft . AspNetCore . Builder ;
7+ using Microsoft . AspNetCore . Hosting ;
8+ using Microsoft . AspNetCore . Http ;
79using Microsoft . AspNet . SpaServices . Webpack ;
8- using Microsoft . Extensions . Configuration ;
910using Microsoft . Extensions . DependencyInjection ;
1011using Microsoft . Extensions . Logging ;
1112using Newtonsoft . Json . Serialization ;
@@ -14,54 +15,28 @@ namespace WebApplicationBasic
1415{
1516 public class Startup
1617 {
17- public Startup ( IHostingEnvironment env )
18- {
19- // Set up configuration sources.
20- var builder = new ConfigurationBuilder ( )
21- . AddJsonFile ( "appsettings.json" )
22- . AddEnvironmentVariables ( ) ;
23- Configuration = builder . Build ( ) ;
24- }
25-
26- public IConfigurationRoot Configuration { get ; set ; }
27-
2818 // This method gets called by the runtime. Use this method to add services to the container.
2919 public void ConfigureServices ( IServiceCollection services )
3020 {
31- // Add framework services.
3221 services . AddMvc ( ) . AddJsonOptions ( options =>
3322 {
3423 options . SerializerSettings . ContractResolver = new CamelCasePropertyNamesContractResolver ( ) ;
3524 } ) ;
3625 }
3726
3827 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
39- public void Configure ( IApplicationBuilder app , IHostingEnvironment env , ILoggerFactory loggerFactory )
28+ public void Configure ( IApplicationBuilder app , ILoggerFactory loggerFactory , IHostingEnvironment env )
4029 {
41- loggerFactory . AddConsole ( Configuration . GetSection ( "Logging" ) ) ;
42- loggerFactory . AddDebug ( ) ;
30+ app . UseDeveloperExceptionPage ( ) ;
4331
44- if ( env . IsDevelopment ( ) )
45- {
46- app . UseDeveloperExceptionPage ( ) ;
47- }
48- else
49- {
50- app . UseExceptionHandler ( "/Home/Error" ) ;
51- }
52-
53- app . UseIISPlatformHandler ( ) ;
54-
55- if ( env . IsDevelopment ( ) )
56- {
57- app . UseWebpackDevMiddleware ( new WebpackDevMiddlewareOptions
58- {
32+ if ( env . IsDevelopment ( ) ) {
33+ app . UseWebpackDevMiddleware ( new WebpackDevMiddlewareOptions {
5934 HotModuleReplacement = true
6035 } ) ;
6136 }
6237
6338 app . UseStaticFiles ( ) ;
64-
39+ loggerFactory . AddConsole ( ) ;
6540 app . UseMvc ( routes =>
6641 {
6742 routes . MapRoute (
@@ -74,7 +49,17 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
7449 } ) ;
7550 }
7651
77- // Entry point for the application.
78- public static void Main ( string [ ] args ) => Microsoft . AspNet . Hosting . WebApplication . Run < Startup > ( args ) ;
52+ public static void Main ( string [ ] args )
53+ {
54+ var host = new WebHostBuilder ( )
55+ . UseContentRoot ( Directory . GetCurrentDirectory ( ) )
56+ . UseDefaultHostingConfiguration ( args )
57+ . UseIISPlatformHandlerUrl ( )
58+ . UseKestrel ( )
59+ . UseStartup < Startup > ( )
60+ . Build ( ) ;
61+
62+ host . Run ( ) ;
63+ }
7964 }
8065}
0 commit comments