Skip to content

Commit acdae87

Browse files
committed
Fixing obsoletion and improved message
1 parent fbd861f commit acdae87

File tree

11 files changed

+39
-37
lines changed

11 files changed

+39
-37
lines changed

src/Servers/Kestrel/Core/src/Internal/Certificates/CertificateConfigLoader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Certificates
1414
{
1515
internal class CertificateConfigLoader : ICertificateConfigLoader
1616
{
17-
public CertificateConfigLoader(IHostEnvironment hostEnvironment, ILogger<KestrelServer> logger)
17+
public CertificateConfigLoader(IHostEnvironment hostEnvironment, ILogger<KestrelServerImpl> logger)
1818
{
1919
HostEnvironment = hostEnvironment;
2020
Logger = logger;
2121
}
2222

2323
public IHostEnvironment HostEnvironment { get; }
24-
public ILogger<KestrelServer> Logger { get; }
24+
public ILogger<KestrelServerImpl> Logger { get; }
2525

2626
public bool IsTestMock => false;
2727

src/Servers/Kestrel/Core/src/Internal/LoggerExtensions.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,20 @@ internal static class LoggerExtensions
5858
new EventId(7, "MissingOrInvalidCertificateKeyFile"),
5959
"The certificate key file at '{CertificateKeyFilePath}' can not be found, contains malformed data or does not contain a PEM encoded key in PKCS8 format.");
6060

61-
public static void LocatedDevelopmentCertificate(this ILogger<KestrelServer> logger, X509Certificate2 certificate) => _locatedDevelopmentCertificate(logger, certificate.Subject, certificate.Thumbprint, null);
61+
public static void LocatedDevelopmentCertificate(this ILogger<KestrelServerImpl> logger, X509Certificate2 certificate) => _locatedDevelopmentCertificate(logger, certificate.Subject, certificate.Thumbprint, null);
6262

63-
public static void UnableToLocateDevelopmentCertificate(this ILogger<KestrelServer> logger) => _unableToLocateDevelopmentCertificate(logger, null);
63+
public static void UnableToLocateDevelopmentCertificate(this ILogger<KestrelServerImpl> logger) => _unableToLocateDevelopmentCertificate(logger, null);
6464

65-
public static void FailedToLocateDevelopmentCertificateFile(this ILogger<KestrelServer> logger, string certificatePath) => _failedToLocateDevelopmentCertificateFile(logger, certificatePath, null);
65+
public static void FailedToLocateDevelopmentCertificateFile(this ILogger<KestrelServerImpl> logger, string certificatePath) => _failedToLocateDevelopmentCertificateFile(logger, certificatePath, null);
6666

67-
public static void FailedToLoadDevelopmentCertificate(this ILogger<KestrelServer> logger, string certificatePath) => _failedToLoadDevelopmentCertificate(logger, certificatePath, null);
67+
public static void FailedToLoadDevelopmentCertificate(this ILogger<KestrelServerImpl> logger, string certificatePath) => _failedToLoadDevelopmentCertificate(logger, certificatePath, null);
6868

69-
public static void BadDeveloperCertificateState(this ILogger<KestrelServer> logger) => _badDeveloperCertificateState(logger, null);
69+
public static void BadDeveloperCertificateState(this ILogger<KestrelServerImpl> logger) => _badDeveloperCertificateState(logger, null);
7070

71-
public static void DeveloperCertificateFirstRun(this ILogger<KestrelServer> logger, string message) => _developerCertificateFirstRun(logger, message, null);
71+
public static void DeveloperCertificateFirstRun(this ILogger<KestrelServerImpl> logger, string message) => _developerCertificateFirstRun(logger, message, null);
7272

73-
public static void FailedToLoadCertificate(this ILogger<KestrelServer> logger, string certificatePath) => _failedToLoadCertificate(logger, certificatePath, null);
73+
public static void FailedToLoadCertificate(this ILogger<KestrelServerImpl> logger, string certificatePath) => _failedToLoadCertificate(logger, certificatePath, null);
7474

75-
public static void FailedToLoadCertificateKey(this ILogger<KestrelServer> logger, string certificateKeyPath) => _failedToLoadCertificateKey(logger, certificateKeyPath, null);
75+
public static void FailedToLoadCertificateKey(this ILogger<KestrelServerImpl> logger, string certificateKeyPath) => _failedToLoadCertificateKey(logger, certificateKeyPath, null);
7676
}
7777
}

src/Servers/Kestrel/Core/src/KestrelConfigurationLoader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal KestrelConfigurationLoader(
3030
IConfiguration configuration,
3131
IHostEnvironment hostEnvironment,
3232
bool reloadOnChange,
33-
ILogger<KestrelServer> logger,
33+
ILogger<KestrelServerImpl> logger,
3434
ILogger<HttpsConnectionMiddleware> httpsLogger)
3535
{
3636
Options = options ?? throw new ArgumentNullException(nameof(options));
@@ -55,7 +55,7 @@ internal KestrelConfigurationLoader(
5555
internal bool ReloadOnChange { get; }
5656

5757
private IHostEnvironment HostEnvironment { get; }
58-
private ILogger<KestrelServer> Logger { get; }
58+
private ILogger<KestrelServerImpl> Logger { get; }
5959
private ILogger<HttpsConnectionMiddleware> HttpsLogger { get; }
6060

6161
private ConfigurationReader ConfigurationReader { get; set; }

src/Servers/Kestrel/Core/src/KestrelServer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
namespace Microsoft.AspNetCore.Server.Kestrel.Core
1616
{
17-
[Obsolete("This type is obsolete and will be removed in a future version.")]
17+
[Obsolete("This type is obsolete and will be removed in a future version. " +
18+
"Instead, you can resolve the server by calling IWebHostBuilder.UseKestrel()" +
19+
" and resolving the IServer through the built host (ex: IHost.Services.GetRequiredService<IServer>())")]
1820
public class KestrelServer : IServer
1921
{
2022
private KestrelServerImpl _innerKestrelServer;

src/Servers/Kestrel/Core/src/KestrelServerOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ private void EnsureDefaultCert()
177177
if (DefaultCertificate == null && !IsDevCertLoaded)
178178
{
179179
IsDevCertLoaded = true; // Only try once
180-
var logger = ApplicationServices!.GetRequiredService<ILogger<KestrelServer>>();
180+
var logger = ApplicationServices!.GetRequiredService<ILogger<KestrelServerImpl>>();
181181
try
182182
{
183183
DefaultCertificate = CertificateManager.Instance.ListCertificates(StoreName.My, StoreLocation.CurrentUser, isValid: true)
@@ -250,7 +250,7 @@ public KestrelConfigurationLoader Configure(IConfiguration config, bool reloadOn
250250
}
251251

252252
var hostEnvironment = ApplicationServices.GetRequiredService<IHostEnvironment>();
253-
var logger = ApplicationServices.GetRequiredService<ILogger<KestrelServer>>();
253+
var logger = ApplicationServices.GetRequiredService<ILogger<KestrelServerImpl>>();
254254
var httpsLogger = ApplicationServices.GetRequiredService<ILogger<HttpsConnectionMiddleware>>();
255255

256256
var loader = new KestrelConfigurationLoader(this, config, hostEnvironment, reloadOnChange, logger, httpsLogger);

src/Servers/Kestrel/Core/test/KestrelEventSourceTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -13,7 +13,7 @@ public class KestrelEventSourceTests
1313
[Fact]
1414
public void ExistsWithCorrectId()
1515
{
16-
var esType = typeof(KestrelServer).GetTypeInfo().Assembly.GetType(
16+
var esType = typeof(KestrelServerImpl).GetTypeInfo().Assembly.GetType(
1717
"Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.KestrelEventSource",
1818
throwOnError: true,
1919
ignoreCase: false

src/Servers/Kestrel/Core/test/KestrelServerOptionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void CanCallListenAfterConfigure()
8282
// Ensure configure doesn't throw because of missing services.
8383
var serviceCollection = new ServiceCollection();
8484
serviceCollection.AddSingleton(Mock.Of<IHostEnvironment>());
85-
serviceCollection.AddSingleton(Mock.Of<ILogger<KestrelServer>>());
85+
serviceCollection.AddSingleton(Mock.Of<ILogger<KestrelServerImpl>>());
8686
serviceCollection.AddSingleton(Mock.Of<ILogger<HttpsConnectionMiddleware>>());
8787
options.ApplicationServices = serviceCollection.BuildServiceProvider();
8888

src/Servers/Kestrel/Core/test/KestrelServerTests.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,15 @@ public void LoggerCategoryNameIsKestrelServerNamespace()
208208
var mockLoggerFactory = new Mock<ILoggerFactory>();
209209
var mockLogger = new Mock<ILogger>();
210210
mockLoggerFactory.Setup(m => m.CreateLogger(It.IsAny<string>())).Returns(mockLogger.Object);
211-
new KestrelServer(Options.Create<KestrelServerOptions>(null), new List<IConnectionListenerFactory>() { new MockTransportFactory() }, mockLoggerFactory.Object);
211+
new KestrelServerImpl(Options.Create<KestrelServerOptions>(null), new List<IConnectionListenerFactory>() { new MockTransportFactory() }, mockLoggerFactory.Object);
212212
mockLoggerFactory.Verify(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel"));
213213
}
214214

215215
[Fact]
216216
public void ConstructorWithNullTransportFactoriesThrows()
217217
{
218218
var exception = Assert.Throws<ArgumentNullException>(() =>
219-
new KestrelServer(
219+
new KestrelServerImpl(
220220
Options.Create<KestrelServerOptions>(null),
221221
null,
222222
new LoggerFactory(new[] { new KestrelTestLoggerProvider() })));
@@ -228,7 +228,7 @@ public void ConstructorWithNullTransportFactoriesThrows()
228228
public void ConstructorWithNoTransportFactoriesThrows()
229229
{
230230
var exception = Assert.Throws<InvalidOperationException>(() =>
231-
new KestrelServer(
231+
new KestrelServerImpl(
232232
Options.Create<KestrelServerOptions>(null),
233233
new List<IConnectionListenerFactory>(),
234234
new LoggerFactory(new[] { new KestrelTestLoggerProvider() })));
@@ -239,7 +239,7 @@ public void ConstructorWithNoTransportFactoriesThrows()
239239
[Fact]
240240
public void StartWithMultipleTransportFactoriesDoesNotThrow()
241241
{
242-
using var server = new KestrelServer(
242+
using var server = new KestrelServerImpl(
243243
Options.Create(CreateServerOptions()),
244244
new List<IConnectionListenerFactory>() { new ThrowingTransportFactory(), new MockTransportFactory() },
245245
new LoggerFactory(new[] { new KestrelTestLoggerProvider() }));
@@ -285,7 +285,7 @@ public async Task StopAsyncCallsCompleteWhenFirstCallCompletes()
285285
var mockLoggerFactory = new Mock<ILoggerFactory>();
286286
var mockLogger = new Mock<ILogger>();
287287
mockLoggerFactory.Setup(m => m.CreateLogger(It.IsAny<string>())).Returns(mockLogger.Object);
288-
var server = new KestrelServer(Options.Create(options), new List<IConnectionListenerFactory>() { mockTransportFactory.Object }, mockLoggerFactory.Object);
288+
var server = new KestrelServerImpl(Options.Create(options), new List<IConnectionListenerFactory>() { mockTransportFactory.Object }, mockLoggerFactory.Object);
289289
await server.StartAsync(new DummyApplication(), CancellationToken.None);
290290

291291
var stopTask1 = server.StopAsync(default);
@@ -343,7 +343,7 @@ public async Task StopAsyncCallsCompleteWithThrownException()
343343
var mockLoggerFactory = new Mock<ILoggerFactory>();
344344
var mockLogger = new Mock<ILogger>();
345345
mockLoggerFactory.Setup(m => m.CreateLogger(It.IsAny<string>())).Returns(mockLogger.Object);
346-
var server = new KestrelServer(Options.Create(options), new List<IConnectionListenerFactory>() { mockTransportFactory.Object }, mockLoggerFactory.Object);
346+
var server = new KestrelServerImpl(Options.Create(options), new List<IConnectionListenerFactory>() { mockTransportFactory.Object }, mockLoggerFactory.Object);
347347
await server.StartAsync(new DummyApplication(), CancellationToken.None);
348348

349349
var stopTask1 = server.StopAsync(default);
@@ -398,7 +398,7 @@ public async Task StopAsyncDispatchesSubsequentStopAsyncContinuations()
398398
var mockLoggerFactory = new Mock<ILoggerFactory>();
399399
var mockLogger = new Mock<ILogger>();
400400
mockLoggerFactory.Setup(m => m.CreateLogger(It.IsAny<string>())).Returns(mockLogger.Object);
401-
var server = new KestrelServer(Options.Create(options), new List<IConnectionListenerFactory>() { mockTransportFactory.Object }, mockLoggerFactory.Object);
401+
var server = new KestrelServerImpl(Options.Create(options), new List<IConnectionListenerFactory>() { mockTransportFactory.Object }, mockLoggerFactory.Object);
402402
await server.StartAsync(new DummyApplication(), default);
403403

404404
var stopTask1 = server.StopAsync(default);
@@ -444,7 +444,7 @@ public void StartingServerInitializesHeartbeat()
444444
DebuggerWrapper.Singleton,
445445
testContext.Log);
446446

447-
using (var server = new KestrelServer(new List<IConnectionListenerFactory>() { new MockTransportFactory() }, testContext))
447+
using (var server = new KestrelServerImpl(new List<IConnectionListenerFactory>() { new MockTransportFactory() }, testContext))
448448
{
449449
Assert.Null(testContext.DateHeaderValueManager.GetDateHeaderValues());
450450

@@ -496,7 +496,7 @@ public async Task ReloadsOnConfigurationChangeWhenOptedIn()
496496

497497
var serviceCollection = new ServiceCollection();
498498
serviceCollection.AddSingleton(Mock.Of<IHostEnvironment>());
499-
serviceCollection.AddSingleton(Mock.Of<ILogger<KestrelServer>>());
499+
serviceCollection.AddSingleton(Mock.Of<ILogger<KestrelServerImpl>>());
500500
serviceCollection.AddSingleton(Mock.Of<ILogger<HttpsConnectionMiddleware>>());
501501

502502
var options = new KestrelServerOptions
@@ -526,7 +526,7 @@ public async Task ReloadsOnConfigurationChangeWhenOptedIn()
526526
});
527527

528528
// Don't use "using". Dispose() could hang if test fails.
529-
var server = new KestrelServer(Options.Create(options), new List<IConnectionListenerFactory>() { mockTransportFactory.Object }, mockLoggerFactory.Object);
529+
var server = new KestrelServerImpl(Options.Create(options), new List<IConnectionListenerFactory>() { mockTransportFactory.Object }, mockLoggerFactory.Object);
530530

531531
await server.StartAsync(new DummyApplication(), CancellationToken.None).DefaultTimeout();
532532

@@ -633,7 +633,7 @@ public async Task DoesNotReloadOnConfigurationChangeByDefault()
633633

634634
var serviceCollection = new ServiceCollection();
635635
serviceCollection.AddSingleton(Mock.Of<IHostEnvironment>());
636-
serviceCollection.AddSingleton(Mock.Of<ILogger<KestrelServer>>());
636+
serviceCollection.AddSingleton(Mock.Of<ILogger<KestrelServerImpl>>());
637637
serviceCollection.AddSingleton(Mock.Of<ILogger<HttpsConnectionMiddleware>>());
638638

639639
var options = new KestrelServerOptions
@@ -663,7 +663,7 @@ public async Task DoesNotReloadOnConfigurationChangeByDefault()
663663
});
664664

665665
// Don't use "using". Dispose() could hang if test fails.
666-
var server = new KestrelServer(Options.Create(options), new List<IConnectionListenerFactory>() { mockTransportFactory.Object }, mockLoggerFactory.Object);
666+
var server = new KestrelServerImpl(Options.Create(options), new List<IConnectionListenerFactory>() { mockTransportFactory.Object }, mockLoggerFactory.Object);
667667

668668
await server.StartAsync(new DummyApplication(), CancellationToken.None).DefaultTimeout();
669669

@@ -675,14 +675,14 @@ public async Task DoesNotReloadOnConfigurationChangeByDefault()
675675
await server.StopAsync(CancellationToken.None).DefaultTimeout();
676676
}
677677

678-
private static KestrelServer CreateServer(KestrelServerOptions options, ILogger testLogger)
678+
private static KestrelServerImpl CreateServer(KestrelServerOptions options, ILogger testLogger)
679679
{
680-
return new KestrelServer(Options.Create(options), new List<IConnectionListenerFactory>() { new MockTransportFactory() }, new LoggerFactory(new[] { new KestrelTestLoggerProvider(testLogger) }));
680+
return new KestrelServerImpl(Options.Create(options), new List<IConnectionListenerFactory>() { new MockTransportFactory() }, new LoggerFactory(new[] { new KestrelTestLoggerProvider(testLogger) }));
681681
}
682682

683-
private static KestrelServer CreateServer(KestrelServerOptions options, bool throwOnCriticalErrors = true)
683+
private static KestrelServerImpl CreateServer(KestrelServerOptions options, bool throwOnCriticalErrors = true)
684684
{
685-
return new KestrelServer(Options.Create(options), new List<IConnectionListenerFactory>() { new MockTransportFactory() }, new LoggerFactory(new[] { new KestrelTestLoggerProvider(throwOnCriticalErrors) }));
685+
return new KestrelServerImpl(Options.Create(options), new List<IConnectionListenerFactory>() { new MockTransportFactory() }, new LoggerFactory(new[] { new KestrelTestLoggerProvider(throwOnCriticalErrors) }));
686686
}
687687

688688
private static void StartDummyApplication(IServer server)

src/Servers/Kestrel/shared/test/TransportTestHelpers/TestServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public TestServer(RequestDelegate app, TestServiceContext context, Action<Kestre
9393
c.Configure(context.ServerOptions);
9494
}
9595

96-
return new KestrelServer(new List<IConnectionListenerFactory>() { sp.GetRequiredService<IConnectionListenerFactory>() }, context);
96+
return new KestrelServerImpl(new List<IConnectionListenerFactory>() { sp.GetRequiredService<IConnectionListenerFactory>() }, context);
9797
});
9898
configureServices(services);
9999
})

src/Servers/Kestrel/test/InMemory.FunctionalTests/HttpsConnectionMiddlewareTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public async Task CanReadAndWriteWithHttpsConnectionMiddlewareWithPemCertificate
7272
var serviceProvider = new ServiceCollection().AddLogging().BuildServiceProvider();
7373
options.ApplicationServices = serviceProvider;
7474

75-
var logger = serviceProvider.GetRequiredService<ILogger<KestrelServer>>();
75+
var logger = serviceProvider.GetRequiredService<ILogger<KestrelServerImpl>>();
7676
var httpsLogger = serviceProvider.GetRequiredService<ILogger<HttpsConnectionMiddleware>>();
7777
var loader = new KestrelConfigurationLoader(options, configuration, env.Object, reloadOnChange: false, logger, httpsLogger);
7878
loader.Load();

0 commit comments

Comments
 (0)