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,55 +15,29 @@ 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 ReactHotModuleReplacement = true
6136 } ) ;
6237 }
6338
6439 app . UseStaticFiles ( ) ;
65-
40+ loggerFactory . AddConsole ( ) ;
6641 app . UseMvc ( routes =>
6742 {
6843 routes . MapRoute (
@@ -75,7 +50,17 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
7550 } ) ;
7651 }
7752
78- // Entry point for the application.
79- public static void Main ( string [ ] args ) => Microsoft . AspNet . Hosting . WebApplication . Run < Startup > ( args ) ;
53+ public static void Main ( string [ ] args )
54+ {
55+ var host = new WebHostBuilder ( )
56+ . UseContentRoot ( Directory . GetCurrentDirectory ( ) )
57+ . UseDefaultHostingConfiguration ( args )
58+ . UseIISPlatformHandlerUrl ( )
59+ . UseKestrel ( )
60+ . UseStartup < Startup > ( )
61+ . Build ( ) ;
62+
63+ host . Run ( ) ;
64+ }
8065 }
8166}
0 commit comments