From b571246c93563b921d72027b999c461359ffc5c6 Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 15 Feb 2019 18:56:05 -0800 Subject: [PATCH] Suppress warnings for obsolete Extensions types --- .../GenericWebHostApplicationLifetime.cs | 4 +++- .../Hosting/src/Internal/ApplicationLifetime.cs | 3 ++- .../Hosting/src/Internal/HostingEnvironment.cs | 4 +++- src/Hosting/Hosting/src/Internal/WebHost.cs | 2 ++ src/Hosting/Hosting/src/WebHostBuilder.cs | 2 ++ src/Hosting/Hosting/test/WebHostBuilderTests.cs | 12 ++++++++++++ src/Hosting/Hosting/test/WebHostTests.cs | 16 ++++++++++++++++ 7 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/Hosting/Hosting/src/GenericHost/GenericWebHostApplicationLifetime.cs b/src/Hosting/Hosting/src/GenericHost/GenericWebHostApplicationLifetime.cs index d95704154e..53fe0132b7 100644 --- a/src/Hosting/Hosting/src/GenericHost/GenericWebHostApplicationLifetime.cs +++ b/src/Hosting/Hosting/src/GenericHost/GenericWebHostApplicationLifetime.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading; @@ -7,8 +7,10 @@ namespace Microsoft.AspNetCore.Hosting.Internal { internal class GenericWebHostApplicationLifetime : IApplicationLifetime { +#pragma warning disable CS0618 // Type or member is obsolete private readonly Microsoft.Extensions.Hosting.IApplicationLifetime _applicationLifetime; public GenericWebHostApplicationLifetime(Microsoft.Extensions.Hosting.IApplicationLifetime applicationLifetime) +#pragma warning restore CS0618 // Type or member is obsolete { _applicationLifetime = applicationLifetime; } diff --git a/src/Hosting/Hosting/src/Internal/ApplicationLifetime.cs b/src/Hosting/Hosting/src/Internal/ApplicationLifetime.cs index 958f8b5dcc..342ba6485b 100644 --- a/src/Hosting/Hosting/src/Internal/ApplicationLifetime.cs +++ b/src/Hosting/Hosting/src/Internal/ApplicationLifetime.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.Threading; using Microsoft.Extensions.Logging; @@ -11,7 +10,9 @@ namespace Microsoft.AspNetCore.Hosting.Internal /// /// Allows consumers to perform cleanup during a graceful shutdown. /// +#pragma warning disable CS0618 // Type or member is obsolete public class ApplicationLifetime : IApplicationLifetime, Extensions.Hosting.IApplicationLifetime +#pragma warning restore CS0618 // Type or member is obsolete { private readonly CancellationTokenSource _startedSource = new CancellationTokenSource(); private readonly CancellationTokenSource _stoppingSource = new CancellationTokenSource(); diff --git a/src/Hosting/Hosting/src/Internal/HostingEnvironment.cs b/src/Hosting/Hosting/src/Internal/HostingEnvironment.cs index 1f8d1887d7..6bd7d57632 100644 --- a/src/Hosting/Hosting/src/Internal/HostingEnvironment.cs +++ b/src/Hosting/Hosting/src/Internal/HostingEnvironment.cs @@ -5,7 +5,9 @@ using Microsoft.Extensions.FileProviders; namespace Microsoft.AspNetCore.Hosting.Internal { +#pragma warning disable CS0618 // Type or member is obsolete public class HostingEnvironment : IHostingEnvironment, Extensions.Hosting.IHostingEnvironment +#pragma warning restore CS0618 // Type or member is obsolete { public string EnvironmentName { get; set; } = Hosting.EnvironmentName.Production; @@ -19,4 +21,4 @@ namespace Microsoft.AspNetCore.Hosting.Internal public IFileProvider ContentRootFileProvider { get; set; } } -} \ No newline at end of file +} diff --git a/src/Hosting/Hosting/src/Internal/WebHost.cs b/src/Hosting/Hosting/src/Internal/WebHost.cs index 1bd9f3c2a0..b32726cbb5 100644 --- a/src/Hosting/Hosting/src/Internal/WebHost.cs +++ b/src/Hosting/Hosting/src/Internal/WebHost.cs @@ -80,7 +80,9 @@ namespace Microsoft.AspNetCore.Hosting.Internal // There's no way to to register multiple service types per definition. See https://github.com/aspnet/DependencyInjection/issues/360 _applicationServiceCollection.AddSingleton(sp => { +#pragma warning disable CS0618 // Type or member is obsolete return sp.GetRequiredService() as Extensions.Hosting.IApplicationLifetime; +#pragma warning restore CS0618 // Type or member is obsolete }); _applicationServiceCollection.AddSingleton(); } diff --git a/src/Hosting/Hosting/src/WebHostBuilder.cs b/src/Hosting/Hosting/src/WebHostBuilder.cs index 9bcb9e3b09..ddce2b8116 100644 --- a/src/Hosting/Hosting/src/WebHostBuilder.cs +++ b/src/Hosting/Hosting/src/WebHostBuilder.cs @@ -254,7 +254,9 @@ namespace Microsoft.AspNetCore.Hosting var services = new ServiceCollection(); services.AddSingleton(_options); services.AddSingleton(_hostingEnvironment); +#pragma warning disable CS0618 // Type or member is obsolete services.AddSingleton(_hostingEnvironment); +#pragma warning restore CS0618 // Type or member is obsolete services.AddSingleton(_context); var builder = new ConfigurationBuilder() diff --git a/src/Hosting/Hosting/test/WebHostBuilderTests.cs b/src/Hosting/Hosting/test/WebHostBuilderTests.cs index 1882f4628f..e04434bb70 100644 --- a/src/Hosting/Hosting/test/WebHostBuilderTests.cs +++ b/src/Hosting/Hosting/test/WebHostBuilderTests.cs @@ -552,7 +552,9 @@ namespace Microsoft.AspNetCore.Hosting .Build()) { Assert.Equal(expected, host.Services.GetService().EnvironmentName); +#pragma warning disable CS0618 // Type or member is obsolete Assert.Equal(expected, host.Services.GetService().EnvironmentName); +#pragma warning restore CS0618 // Type or member is obsolete } } @@ -597,7 +599,9 @@ namespace Microsoft.AspNetCore.Hosting .Build()) { Assert.Equal("/", host.Services.GetService().ContentRootPath); +#pragma warning disable CS0618 // Type or member is obsolete Assert.Equal("/", host.Services.GetService().ContentRootPath); +#pragma warning restore CS0618 // Type or member is obsolete } } @@ -612,7 +616,9 @@ namespace Microsoft.AspNetCore.Hosting .Build()) { var basePath = host.Services.GetRequiredService().ContentRootPath; +#pragma warning disable CS0618 // Type or member is obsolete var basePath2 = host.Services.GetService().ContentRootPath; +#pragma warning restore CS0618 // Type or member is obsolete Assert.True(Path.IsPathRooted(basePath)); Assert.EndsWith(Path.DirectorySeparatorChar + "testroot", basePath); @@ -633,7 +639,9 @@ namespace Microsoft.AspNetCore.Hosting { var appBase = AppContext.BaseDirectory; Assert.Equal(appBase, host.Services.GetService().ContentRootPath); +#pragma warning disable CS0618 // Type or member is obsolete Assert.Equal(appBase, host.Services.GetService().ContentRootPath); +#pragma warning restore CS0618 // Type or member is obsolete } } @@ -659,7 +667,9 @@ namespace Microsoft.AspNetCore.Hosting .Build()) { var hostingEnv = host.Services.GetService(); +#pragma warning disable CS0618 // Type or member is obsolete var hostingEnv2 = host.Services.GetService(); +#pragma warning restore CS0618 // Type or member is obsolete Assert.Equal(typeof(Startup).Assembly.GetName().Name, hostingEnv.ApplicationName); Assert.Equal(typeof(Startup).Assembly.GetName().Name, hostingEnv2.ApplicationName); } @@ -675,7 +685,9 @@ namespace Microsoft.AspNetCore.Hosting .Build()) { var hostingEnv = host.Services.GetService(); +#pragma warning disable CS0618 // Type or member is obsolete var hostingEnv2 = host.Services.GetService(); +#pragma warning restore CS0618 // Type or member is obsolete Assert.Equal(typeof(StartupNoServicesNoInterface).Assembly.GetName().Name, hostingEnv.ApplicationName); Assert.Equal(typeof(StartupNoServicesNoInterface).Assembly.GetName().Name, hostingEnv2.ApplicationName); } diff --git a/src/Hosting/Hosting/test/WebHostTests.cs b/src/Hosting/Hosting/test/WebHostTests.cs index 4a6033d7d6..ed4ee43c1e 100644 --- a/src/Hosting/Hosting/test/WebHostTests.cs +++ b/src/Hosting/Hosting/test/WebHostTests.cs @@ -168,7 +168,9 @@ namespace Microsoft.AspNetCore.Hosting .Build()) { var lifetime = host.Services.GetRequiredService(); +#pragma warning disable CS0618 // Type or member is obsolete var lifetime2 = host.Services.GetRequiredService(); +#pragma warning restore CS0618 // Type or member is obsolete var server = (FakeServer)host.Services.GetRequiredService(); var cts = new CancellationTokenSource(); @@ -415,7 +417,9 @@ namespace Microsoft.AspNetCore.Hosting .Build()) { var applicationLifetime = host.Services.GetService(); +#pragma warning disable CS0618 // Type or member is obsolete var applicationLifetime2 = host.Services.GetService(); +#pragma warning restore CS0618 // Type or member is obsolete Assert.False(applicationLifetime.ApplicationStarted.IsCancellationRequested); Assert.False(applicationLifetime2.ApplicationStarted.IsCancellationRequested); @@ -434,7 +438,9 @@ namespace Microsoft.AspNetCore.Hosting .Build()) { var applicationLifetime = host.Services.GetService(); +#pragma warning disable CS0618 // Type or member is obsolete var applicationLifetime2 = host.Services.GetService(); +#pragma warning restore CS0618 // Type or member is obsolete var started = RegisterCallbacksThatThrow(applicationLifetime.ApplicationStarted); var stopping = RegisterCallbacksThatThrow(applicationLifetime.ApplicationStopping); @@ -682,7 +688,9 @@ namespace Microsoft.AspNetCore.Hosting .Build()) { var applicationLifetime = host.Services.GetService(); +#pragma warning disable CS0618 // Type or member is obsolete var applicationLifetime2 = host.Services.GetService(); +#pragma warning restore CS0618 // Type or member is obsolete var started = RegisterCallbacksThatThrow(applicationLifetime.ApplicationStarted); var stopping = RegisterCallbacksThatThrow(applicationLifetime.ApplicationStopping); @@ -714,7 +722,9 @@ namespace Microsoft.AspNetCore.Hosting { await host.StartAsync(); var env = host.Services.GetService(); +#pragma warning disable CS0618 // Type or member is obsolete var env2 = host.Services.GetService(); +#pragma warning restore CS0618 // Type or member is obsolete Assert.Equal("Changed", env.EnvironmentName); Assert.Equal("Changed", env2.EnvironmentName); } @@ -799,7 +809,9 @@ namespace Microsoft.AspNetCore.Hosting using (var host = CreateBuilder().UseFakeServer().Build()) { var env = host.Services.GetService(); +#pragma warning disable CS0618 // Type or member is obsolete var env2 = host.Services.GetService(); +#pragma warning restore CS0618 // Type or member is obsolete Assert.Equal(EnvironmentName.Production, env.EnvironmentName); Assert.Equal(EnvironmentName.Production, env2.EnvironmentName); } @@ -820,7 +832,9 @@ namespace Microsoft.AspNetCore.Hosting using (var host = CreateBuilder(config).UseFakeServer().Build()) { var env = host.Services.GetService(); +#pragma warning disable CS0618 // Type or member is obsolete var env2 = host.Services.GetService(); +#pragma warning restore CS0618 // Type or member is obsolete Assert.Equal(EnvironmentName.Staging, env.EnvironmentName); Assert.Equal(EnvironmentName.Staging, env.EnvironmentName); } @@ -1022,7 +1036,9 @@ namespace Microsoft.AspNetCore.Hosting { private readonly IApplicationLifetime _lifetime; +#pragma warning disable CS0618 // Type or member is obsolete public TestHostedService(IApplicationLifetime lifetime, Extensions.Hosting.IApplicationLifetime lifetime2) +#pragma warning restore CS0618 // Type or member is obsolete { _lifetime = lifetime; }