2626using Microsoft . AspNetCore . Hosting ;
2727using Microsoft . AspNetCore . Server . Kestrel . Core ;
2828using Microsoft . Extensions . DependencyInjection ;
29+ using Microsoft . Extensions . Hosting ;
2930using Microsoft . Extensions . Logging ;
3031
3132namespace BenchmarkWorkerWebsite
@@ -42,7 +43,7 @@ public static IServerRunner CreateStarted(ServerConfig config, ILogger logger)
4243 {
4344 logger . LogInformation ( "ServerConfig: {0}" , config ) ;
4445
45- var webHostBuilder = WebHost . CreateDefaultBuilder ( ) ;
46+ var hostBuilder = Host . CreateDefaultBuilder ( ) ;
4647
4748 if ( config . AsyncServerThreads != 0 )
4849 {
@@ -69,36 +70,39 @@ public static IServerRunner CreateStarted(ServerConfig config, ILogger logger)
6970 logger . LogWarning ( "Grpc.AspNetCore server doesn't support autoselecting of listening port. Setting port explictly to " + port ) ;
7071 }
7172
72- webHostBuilder . ConfigureKestrel ( ( context , options ) =>
73+ hostBuilder . ConfigureWebHostDefaults ( webHostBuilder =>
7374 {
74- options . ListenAnyIP ( port , listenOptions =>
75+ webHostBuilder . ConfigureKestrel ( ( context , options ) =>
7576 {
76- // TODO(jtattermusch): use TLS if config.SecurityParams != null
77- listenOptions . Protocols = HttpProtocols . Http2 ;
77+ options . ListenAnyIP ( port , listenOptions =>
78+ {
79+ // TODO(jtattermusch): use TLS if config.SecurityParams != null
80+ listenOptions . Protocols = HttpProtocols . Http2 ;
81+ } ) ;
7882 } ) ;
79- } ) ;
8083
81- if ( config . ServerType == ServerType . AsyncServer )
82- {
83- GrpcPreconditions . CheckArgument ( config . PayloadConfig == null ,
84- "ServerConfig.PayloadConfig shouldn't be set for BenchmarkService based server." ) ;
85- webHostBuilder . UseStartup < BenchmarkServiceStartup > ( ) ;
86- }
87- else if ( config . ServerType == ServerType . AsyncGenericServer )
88- {
89- var genericService = new GenericServiceImpl ( config . PayloadConfig . BytebufParams . RespSize ) ;
90- // TODO(jtattermusch): use startup with given generic service
91- throw new ArgumentException ( "Generice service is not yet implemented." ) ;
92- }
93- else
94- {
95- throw new ArgumentException ( "Unsupported ServerType" ) ;
96- }
84+ if ( config . ServerType == ServerType . AsyncServer )
85+ {
86+ GrpcPreconditions . CheckArgument ( config . PayloadConfig == null ,
87+ "ServerConfig.PayloadConfig shouldn't be set for BenchmarkService based server." ) ;
88+ webHostBuilder . UseStartup < BenchmarkServiceStartup > ( ) ;
89+ }
90+ else if ( config . ServerType == ServerType . AsyncGenericServer )
91+ {
92+ var genericService = new GenericServiceImpl ( config . PayloadConfig . BytebufParams . RespSize ) ;
93+ // TODO(jtattermusch): use startup with given generic service
94+ throw new ArgumentException ( "Generice service is not yet implemented." ) ;
95+ }
96+ else
97+ {
98+ throw new ArgumentException ( "Unsupported ServerType" ) ;
99+ }
100+ } ) ;
97101
98102 // Don't log requests handled by the benchmarking service
99- webHostBuilder . ConfigureLogging ( logging => logging . SetMinimumLevel ( LogLevel . Warning ) ) ;
103+ hostBuilder . ConfigureLogging ( logging => logging . SetMinimumLevel ( LogLevel . Warning ) ) ;
100104
101- var webHost = webHostBuilder . Build ( ) ;
105+ var webHost = hostBuilder . Build ( ) ;
102106 webHost . Start ( ) ;
103107 return new ServerRunnerImpl ( webHost , logger , port ) ;
104108 }
@@ -150,14 +154,14 @@ await requestStream.ForEachAsync(async request =>
150154 /// </summary>
151155 public class ServerRunnerImpl : IServerRunner
152156 {
153- readonly IWebHost webHost ;
157+ readonly IHost host ;
154158 readonly ILogger logger ;
155159 readonly int boundPort ;
156160 readonly TimeStats timeStats = new TimeStats ( ) ;
157161
158- public ServerRunnerImpl ( IWebHost webHost , ILogger logger , int boundPort )
162+ public ServerRunnerImpl ( IHost host , ILogger logger , int boundPort )
159163 {
160- this . webHost = webHost ;
164+ this . host = host ;
161165 this . logger = logger ;
162166 this . boundPort = boundPort ;
163167 }
@@ -189,7 +193,7 @@ public ServerStats GetStats(bool reset)
189193 /// <returns>Task that finishes when server has shutdown.</returns>
190194 public Task StopAsync ( )
191195 {
192- return webHost . StopAsync ( ) ;
196+ return host . StopAsync ( ) ;
193197 }
194198 }
195199}
0 commit comments