11// Licensed to the .NET Foundation under one or more agreements.
22// The .NET Foundation licenses this file to you under the MIT license.
33
4+ using System . Diagnostics ;
5+ using System . Diagnostics . CodeAnalysis ;
46using System . IO . Pipelines ;
57using System . Net ;
68using System . Net . Security ;
1012using Microsoft . AspNetCore . Server . Kestrel . Core . Internal ;
1113using Microsoft . AspNetCore . Server . Kestrel . Https ;
1214using Microsoft . AspNetCore . Server . Kestrel . Https . Internal ;
13- using Microsoft . Extensions . Hosting ;
14- using Microsoft . Extensions . Logging ;
1515
1616namespace Microsoft . AspNetCore . Server . Kestrel . Core ;
1717
@@ -50,10 +50,7 @@ public HttpsConfigurationService(IInitializer initializer)
5050 bool IHttpsConfigurationService . IsInitialized => _isInitialized || _initializer is not null ;
5151
5252 /// <inheritdoc/>
53- public void Initialize (
54- IHostEnvironment hostEnvironment ,
55- ILogger < KestrelServer > serverLogger ,
56- ILogger < HttpsConnectionMiddleware > httpsLogger )
53+ public void Initialize ( TlsConfigurationLoader tlsConfigurationLoader )
5754 {
5855 if ( _isInitialized )
5956 {
@@ -62,7 +59,7 @@ public void Initialize(
6259
6360 _isInitialized = true ;
6461
65- _tlsConfigurationLoader = new TlsConfigurationLoader ( hostEnvironment , serverLogger , httpsLogger ) ;
62+ _tlsConfigurationLoader = tlsConfigurationLoader ;
6663 _populateMultiplexedTransportFeatures = PopulateMultiplexedTransportFeaturesWorker ;
6764 _useHttpsWithDefaults = UseHttpsWithDefaultsWorker ;
6865 }
@@ -76,41 +73,42 @@ public void ApplyHttpsConfiguration(
7673 ConfigurationReader configurationReader )
7774 {
7875 EnsureInitialized ( ) ;
79- _tlsConfigurationLoader ! . ApplyHttpsConfiguration ( httpsOptions , endpoint , serverOptions , defaultCertificateConfig , configurationReader ) ;
76+ _tlsConfigurationLoader . ApplyHttpsConfiguration ( httpsOptions , endpoint , serverOptions , defaultCertificateConfig , configurationReader ) ;
8077 }
8178
8279 /// <inheritdoc/>
8380 public ListenOptions UseHttpsWithSni ( ListenOptions listenOptions , HttpsConnectionAdapterOptions httpsOptions , EndpointConfig endpoint )
8481 {
8582 EnsureInitialized ( ) ;
86- return _tlsConfigurationLoader ! . UseHttpsWithSni ( listenOptions , httpsOptions , endpoint ) ;
83+ return _tlsConfigurationLoader . UseHttpsWithSni ( listenOptions , httpsOptions , endpoint ) ;
8784 }
8885
8986 /// <inheritdoc/>
9087 public CertificateAndConfig ? LoadDefaultCertificate ( ConfigurationReader configurationReader )
9188 {
9289 EnsureInitialized ( ) ;
93- return _tlsConfigurationLoader ! . LoadDefaultCertificate ( configurationReader ) ;
90+ return _tlsConfigurationLoader . LoadDefaultCertificate ( configurationReader ) ;
9491 }
9592
9693 /// <inheritdoc/>
9794 public void PopulateMultiplexedTransportFeatures ( FeatureCollection features , ListenOptions listenOptions )
9895 {
9996 EnsureInitialized ( ) ;
100- _populateMultiplexedTransportFeatures ! . Invoke ( features , listenOptions ) ;
97+ _populateMultiplexedTransportFeatures . Invoke ( features , listenOptions ) ;
10198 }
10299
103100 /// <inheritdoc/>
104101 public ListenOptions UseHttpsWithDefaults ( ListenOptions listenOptions )
105102 {
106103 EnsureInitialized ( ) ;
107- return _useHttpsWithDefaults ! . Invoke ( listenOptions ) ;
104+ return _useHttpsWithDefaults . Invoke ( listenOptions ) ;
108105 }
109106
110107 /// <summary>
111108 /// If this instance has not been initialized, initialize it if possible and throw otherwise.
112109 /// </summary>
113110 /// <exception cref="InvalidOperationException">If initialization is not possible.</exception>
111+ [ MemberNotNull ( nameof ( _useHttpsWithDefaults ) , nameof ( _tlsConfigurationLoader ) , nameof ( _populateMultiplexedTransportFeatures ) ) ]
114112 private void EnsureInitialized ( )
115113 {
116114 if ( ! _isInitialized )
@@ -124,6 +122,10 @@ private void EnsureInitialized()
124122 throw new InvalidOperationException ( CoreStrings . NeedHttpsConfiguration ) ;
125123 }
126124 }
125+
126+ Debug . Assert ( _useHttpsWithDefaults != null ) ;
127+ Debug . Assert ( _tlsConfigurationLoader != null ) ;
128+ Debug . Assert ( _populateMultiplexedTransportFeatures != null ) ;
127129 }
128130
129131 /// <summary>
@@ -228,24 +230,17 @@ internal interface IInitializer
228230 /// <inheritdoc/>
229231 internal sealed class Initializer : IInitializer
230232 {
231- private readonly IHostEnvironment _hostEnvironment ;
232- private readonly ILogger < KestrelServer > _serverLogger ;
233- private readonly ILogger < HttpsConnectionMiddleware > _httpsLogger ;
234-
235- public Initializer (
236- IHostEnvironment hostEnvironment ,
237- ILogger < KestrelServer > serverLogger ,
238- ILogger < HttpsConnectionMiddleware > httpsLogger )
233+ private readonly TlsConfigurationLoader _configurationLoader ;
234+
235+ public Initializer ( TlsConfigurationLoader configurationLoader )
239236 {
240- _hostEnvironment = hostEnvironment ;
241- _serverLogger = serverLogger ;
242- _httpsLogger = httpsLogger ;
237+ _configurationLoader = configurationLoader ;
243238 }
244239
245240 /// <inheritdoc/>
246241 public void Initialize ( IHttpsConfigurationService httpsConfigurationService )
247242 {
248- httpsConfigurationService . Initialize ( _hostEnvironment , _serverLogger , _httpsLogger ) ;
243+ httpsConfigurationService . Initialize ( _configurationLoader ) ;
249244 }
250245 }
251246}
0 commit comments