diff --git a/src/DefaultBuilder/src/GenericHostBuilderExtensions.cs b/src/DefaultBuilder/src/GenericHostBuilderExtensions.cs
index 37ca82e8e5..201fb26fe0 100644
--- a/src/DefaultBuilder/src/GenericHostBuilderExtensions.cs
+++ b/src/DefaultBuilder/src/GenericHostBuilderExtensions.cs
@@ -25,6 +25,11 @@ namespace Microsoft.Extensions.Hosting
/// The for chaining.
public static IHostBuilder ConfigureWebHostDefaults(this IHostBuilder builder, Action configure)
{
+ if (configure is null)
+ {
+ throw new ArgumentNullException(nameof(configure));
+ }
+
return builder.ConfigureWebHost(webHostBuilder =>
{
WebHost.ConfigureWebDefaults(webHostBuilder);
diff --git a/src/DefaultBuilder/src/Microsoft.AspNetCore.csproj b/src/DefaultBuilder/src/Microsoft.AspNetCore.csproj
index 58513c6253..2c66a8407d 100644
--- a/src/DefaultBuilder/src/Microsoft.AspNetCore.csproj
+++ b/src/DefaultBuilder/src/Microsoft.AspNetCore.csproj
@@ -7,6 +7,7 @@
Microsoft.AspNetCore
true
false
+ enable
diff --git a/src/DefaultBuilder/src/WebHost.cs b/src/DefaultBuilder/src/WebHost.cs
index 2d02a8a437..ff79107d32 100644
--- a/src/DefaultBuilder/src/WebHost.cs
+++ b/src/DefaultBuilder/src/WebHost.cs
@@ -40,9 +40,9 @@ namespace Microsoft.AspNetCore
/// The URL the hosted application will listen on.
/// A delegate that handles requests to the application.
/// A started that hosts the application.
- public static IWebHost Start(string url, RequestDelegate app)
+ public static IWebHost Start(string? url, RequestDelegate app)
{
- var startupAssemblyName = app.GetMethodInfo().DeclaringType.GetTypeInfo().Assembly.GetName().Name;
+ var startupAssemblyName = app.GetMethodInfo().DeclaringType!.GetTypeInfo().Assembly.GetName().Name;
return StartWith(url: url, configureServices: null, app: appBuilder => appBuilder.Run(app), applicationName: startupAssemblyName);
}
@@ -62,9 +62,9 @@ namespace Microsoft.AspNetCore
/// The URL the hosted application will listen on.
/// A delegate that configures the router for handling requests to the application.
/// A started that hosts the application.
- public static IWebHost Start(string url, Action routeBuilder)
+ public static IWebHost Start(string? url, Action routeBuilder)
{
- var startupAssemblyName = routeBuilder.GetMethodInfo().DeclaringType.GetTypeInfo().Assembly.GetName().Name;
+ var startupAssemblyName = routeBuilder.GetMethodInfo().DeclaringType!.GetTypeInfo().Assembly.GetName().Name;
return StartWith(url, services => services.AddRouting(), appBuilder => appBuilder.UseRouter(routeBuilder), applicationName: startupAssemblyName);
}
@@ -84,10 +84,10 @@ namespace Microsoft.AspNetCore
/// The URL the hosted application will listen on.
/// The delegate that configures the .
/// A started that hosts the application.
- public static IWebHost StartWith(string url, Action app) =>
+ public static IWebHost StartWith(string? url, Action app) =>
StartWith(url: url, configureServices: null, app: app, applicationName: null);
- private static IWebHost StartWith(string url, Action configureServices, Action app, string applicationName)
+ private static IWebHost StartWith(string? url, Action? configureServices, Action app, string? applicationName)
{
var builder = CreateDefaultBuilder();
@@ -153,7 +153,7 @@ namespace Microsoft.AspNetCore
///
/// The command line args.
/// The initialized .
- public static IWebHostBuilder CreateDefaultBuilder(string[] args)
+ public static IWebHostBuilder CreateDefaultBuilder(string[]? args)
{
var builder = new WebHostBuilder();
diff --git a/src/Hosting/Hosting/src/Builder/ApplicationBuilderFactory.cs b/src/Hosting/Hosting/src/Builder/ApplicationBuilderFactory.cs
index e9c410370c..01482dc91b 100644
--- a/src/Hosting/Hosting/src/Builder/ApplicationBuilderFactory.cs
+++ b/src/Hosting/Hosting/src/Builder/ApplicationBuilderFactory.cs
@@ -1,6 +1,8 @@
// 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.
+#nullable enable
+
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http.Features;
diff --git a/src/Hosting/Hosting/src/Http/DefaultHttpContextFactory.cs b/src/Hosting/Hosting/src/Http/DefaultHttpContextFactory.cs
index 2637a8b3a6..9686aacb45 100644
--- a/src/Hosting/Hosting/src/Http/DefaultHttpContextFactory.cs
+++ b/src/Hosting/Hosting/src/Http/DefaultHttpContextFactory.cs
@@ -1,6 +1,8 @@
// 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.
+#nullable enable
+
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
@@ -12,7 +14,7 @@ namespace Microsoft.AspNetCore.Http
{
public class DefaultHttpContextFactory : IHttpContextFactory
{
- private readonly IHttpContextAccessor _httpContextAccessor;
+ private readonly IHttpContextAccessor? _httpContextAccessor;
private readonly FormOptions _formOptions;
private readonly IServiceScopeFactory _serviceScopeFactory;
@@ -26,7 +28,7 @@ namespace Microsoft.AspNetCore.Http
_serviceScopeFactory = serviceProvider.GetRequiredService();
}
- internal IHttpContextAccessor HttpContextAccessor => _httpContextAccessor;
+ internal IHttpContextAccessor? HttpContextAccessor => _httpContextAccessor;
public HttpContext Create(IFeatureCollection featureCollection)
{
diff --git a/src/Hosting/Hosting/src/Microsoft.AspNetCore.Hosting.csproj b/src/Hosting/Hosting/src/Microsoft.AspNetCore.Hosting.csproj
index c0e3e77284..de44d964bb 100644
--- a/src/Hosting/Hosting/src/Microsoft.AspNetCore.Hosting.csproj
+++ b/src/Hosting/Hosting/src/Microsoft.AspNetCore.Hosting.csproj
@@ -8,6 +8,7 @@
true
aspnetcore;hosting
false
+ 9.0
diff --git a/src/Hosting/Hosting/src/Server/Features/ServerAddressesFeature.cs b/src/Hosting/Hosting/src/Server/Features/ServerAddressesFeature.cs
index 098ec8cdb0..3b4c161f60 100644
--- a/src/Hosting/Hosting/src/Server/Features/ServerAddressesFeature.cs
+++ b/src/Hosting/Hosting/src/Server/Features/ServerAddressesFeature.cs
@@ -1,6 +1,8 @@
// 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.
+#nullable enable
+
using System.Collections.Generic;
namespace Microsoft.AspNetCore.Hosting.Server.Features
diff --git a/src/Hosting/Hosting/src/Startup/DelegateStartup.cs b/src/Hosting/Hosting/src/Startup/DelegateStartup.cs
index d354ad946e..0c1bcb5c04 100644
--- a/src/Hosting/Hosting/src/Startup/DelegateStartup.cs
+++ b/src/Hosting/Hosting/src/Startup/DelegateStartup.cs
@@ -1,6 +1,8 @@
// 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.
+#nullable enable
+
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
@@ -18,4 +20,4 @@ namespace Microsoft.AspNetCore.Hosting
public override void Configure(IApplicationBuilder app) => _configureApp(app);
}
-}
\ No newline at end of file
+}
diff --git a/src/Hosting/Hosting/src/StaticWebAssets/StaticWebAssetsLoader.cs b/src/Hosting/Hosting/src/StaticWebAssets/StaticWebAssetsLoader.cs
index 60d0f8181d..6b9ee360d4 100644
--- a/src/Hosting/Hosting/src/StaticWebAssets/StaticWebAssetsLoader.cs
+++ b/src/Hosting/Hosting/src/StaticWebAssets/StaticWebAssetsLoader.cs
@@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
-using System.Collections.Generic;
+
using System.IO;
using System.Linq;
using System.Reflection;
diff --git a/src/Hosting/Hosting/src/WebHostBuilder.cs b/src/Hosting/Hosting/src/WebHostBuilder.cs
index 68568ffb27..a4b9373234 100644
--- a/src/Hosting/Hosting/src/WebHostBuilder.cs
+++ b/src/Hosting/Hosting/src/WebHostBuilder.cs
@@ -1,9 +1,12 @@
// 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.
+#nullable enable
+
using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection;
@@ -24,13 +27,13 @@ namespace Microsoft.AspNetCore.Hosting
public class WebHostBuilder : IWebHostBuilder
{
private readonly HostingEnvironment _hostingEnvironment;
- private Action _configureServices;
+ private readonly IConfiguration _config;
+ private readonly WebHostBuilderContext _context;
- private IConfiguration _config;
- private WebHostOptions _options;
- private WebHostBuilderContext _context;
+ private WebHostOptions? _options;
private bool _webHostBuilt;
- private Action _configureAppConfigurationBuilder;
+ private Action? _configureServices;
+ private Action? _configureAppConfigurationBuilder;
///
/// Initializes a new instance of the class.
@@ -78,7 +81,7 @@ namespace Microsoft.AspNetCore.Hosting
/// The key of the setting to add or replace.
/// The value of the setting to add or replace.
/// The .
- public IWebHostBuilder UseSetting(string key, string value)
+ public IWebHostBuilder UseSetting(string key, string? value)
{
_config[key] = value;
return this;
@@ -212,7 +215,8 @@ namespace Microsoft.AspNetCore.Hosting
}
}
- private IServiceCollection BuildCommonServices(out AggregateException hostingStartupErrors)
+ [MemberNotNull(nameof(_options))]
+ private IServiceCollection BuildCommonServices(out AggregateException? hostingStartupErrors)
{
hostingStartupErrors = null;
@@ -231,7 +235,7 @@ namespace Microsoft.AspNetCore.Hosting
foreach (var attribute in assembly.GetCustomAttributes())
{
- var hostingStartup = (IHostingStartup)Activator.CreateInstance(attribute.HostingStartupType);
+ var hostingStartup = (IHostingStartup)Activator.CreateInstance(attribute.HostingStartupType)!;
hostingStartup.Configure(this);
}
}
@@ -330,8 +334,8 @@ namespace Microsoft.AspNetCore.Hosting
// NOTE: This code overrides original services lifetime. Instances would always be singleton in
// application container.
var listener = hostingServiceProvider.GetService();
- services.Replace(ServiceDescriptor.Singleton(typeof(DiagnosticListener), listener));
- services.Replace(ServiceDescriptor.Singleton(typeof(DiagnosticSource), listener));
+ services.Replace(ServiceDescriptor.Singleton(typeof(DiagnosticListener), listener!));
+ services.Replace(ServiceDescriptor.Singleton(typeof(DiagnosticSource), listener!));
}
private string ResolveContentRootPath(string contentRootPath, string basePath)
diff --git a/src/Hosting/Hosting/src/WebHostBuilderExtensions.cs b/src/Hosting/Hosting/src/WebHostBuilderExtensions.cs
index 20151ebe9e..252d5c5d43 100644
--- a/src/Hosting/Hosting/src/WebHostBuilderExtensions.cs
+++ b/src/Hosting/Hosting/src/WebHostBuilderExtensions.cs
@@ -1,6 +1,8 @@
// 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.
+#nullable enable
+
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
@@ -25,7 +27,7 @@ namespace Microsoft.AspNetCore.Hosting
/// The .
public static IWebHostBuilder Configure(this IWebHostBuilder hostBuilder, Action configureApp)
{
- return hostBuilder.Configure((_, app) => configureApp(app), configureApp.GetMethodInfo().DeclaringType.GetTypeInfo().Assembly.GetName().Name);
+ return hostBuilder.Configure((_, app) => configureApp(app), configureApp.GetMethodInfo().DeclaringType!.GetTypeInfo().Assembly.GetName().Name!);
}
///
@@ -36,7 +38,7 @@ namespace Microsoft.AspNetCore.Hosting
/// The .
public static IWebHostBuilder Configure(this IWebHostBuilder hostBuilder, Action configureApp)
{
- return hostBuilder.Configure(configureApp, configureApp.GetMethodInfo().DeclaringType.GetTypeInfo().Assembly.GetName().Name);
+ return hostBuilder.Configure(configureApp, configureApp.GetMethodInfo().DeclaringType!.GetTypeInfo().Assembly.GetName().Name!);
}
private static IWebHostBuilder Configure(this IWebHostBuilder hostBuilder, Action configureApp, string startupAssemblyName)
@@ -77,7 +79,7 @@ namespace Microsoft.AspNetCore.Hosting
throw new ArgumentNullException(nameof(startupFactory));
}
- var startupAssemblyName = startupFactory.GetMethodInfo().DeclaringType.GetTypeInfo().Assembly.GetName().Name;
+ var startupAssemblyName = startupFactory.GetMethodInfo().DeclaringType!.GetTypeInfo().Assembly.GetName().Name;
hostBuilder.UseSetting(WebHostDefaults.ApplicationKey, startupAssemblyName);
diff --git a/src/Hosting/Hosting/src/WebHostExtensions.cs b/src/Hosting/Hosting/src/WebHostExtensions.cs
index fe77b13443..f3197e15d3 100644
--- a/src/Hosting/Hosting/src/WebHostExtensions.cs
+++ b/src/Hosting/Hosting/src/WebHostExtensions.cs
@@ -1,6 +1,8 @@
// 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.
+#nullable enable
+
using System;
using System.Threading;
using System.Threading.Tasks;
@@ -103,7 +105,7 @@ namespace Microsoft.AspNetCore.Hosting
}
}
- private static async Task RunAsync(this IWebHost host, CancellationToken token, string startupMessage)
+ private static async Task RunAsync(this IWebHost host, CancellationToken token, string? startupMessage)
{
try
{
@@ -114,8 +116,8 @@ namespace Microsoft.AspNetCore.Hosting
if (!options.SuppressStatusMessages)
{
- Console.WriteLine($"Hosting environment: {hostingEnvironment.EnvironmentName}");
- Console.WriteLine($"Content root path: {hostingEnvironment.ContentRootPath}");
+ Console.WriteLine($"Hosting environment: {hostingEnvironment?.EnvironmentName}");
+ Console.WriteLine($"Content root path: {hostingEnvironment?.ContentRootPath}");
var serverAddresses = host.ServerFeatures.Get()?.Addresses;
@@ -150,18 +152,18 @@ namespace Microsoft.AspNetCore.Hosting
private static async Task WaitForTokenShutdownAsync(this IWebHost host, CancellationToken token)
{
- var applicationLifetime = host.Services.GetService();
+ var applicationLifetime = host.Services.GetRequiredService();
token.Register(state =>
{
- ((IHostApplicationLifetime)state).StopApplication();
+ ((IHostApplicationLifetime)state!).StopApplication();
},
applicationLifetime);
var waitForStop = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
applicationLifetime.ApplicationStopping.Register(obj =>
{
- var tcs = (TaskCompletionSource)obj;
+ var tcs = (TaskCompletionSource)obj!;
tcs.TrySetResult();
}, waitForStop);
diff --git a/src/Hosting/Server.Abstractions/src/IHostContextContainer.cs b/src/Hosting/Server.Abstractions/src/IHostContextContainer.cs
index 603a323912..f413ad451a 100644
--- a/src/Hosting/Server.Abstractions/src/IHostContextContainer.cs
+++ b/src/Hosting/Server.Abstractions/src/IHostContextContainer.cs
@@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Hosting.Server.Abstractions
/// its between requests.
///
/// The Host context
- public interface IHostContextContainer
+ public interface IHostContextContainer where TContext : notnull
{
TContext HostContext { get; set; }
}
diff --git a/src/Hosting/Server.Abstractions/src/IHttpApplication.cs b/src/Hosting/Server.Abstractions/src/IHttpApplication.cs
index cc9d173da6..ea1b660bac 100644
--- a/src/Hosting/Server.Abstractions/src/IHttpApplication.cs
+++ b/src/Hosting/Server.Abstractions/src/IHttpApplication.cs
@@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Hosting.Server
/// Represents an application.
///
/// The context associated with the application.
- public interface IHttpApplication
+ public interface IHttpApplication where TContext : notnull
{
///
/// Create a TContext given a collection of HTTP features.
diff --git a/src/Hosting/Server.Abstractions/src/IServer.cs b/src/Hosting/Server.Abstractions/src/IServer.cs
index b04e5a0d47..78d0f5a32e 100644
--- a/src/Hosting/Server.Abstractions/src/IServer.cs
+++ b/src/Hosting/Server.Abstractions/src/IServer.cs
@@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Hosting.Server
/// An instance of .
/// The context associated with the application.
/// Indicates if the server startup should be aborted.
- Task StartAsync(IHttpApplication application, CancellationToken cancellationToken);
+ Task StartAsync(IHttpApplication application, CancellationToken cancellationToken) where TContext : notnull;
///
/// Stop processing requests and shut down the server, gracefully if possible.
diff --git a/src/Hosting/Server.Abstractions/src/IServerIntegratedAuth.cs b/src/Hosting/Server.Abstractions/src/IServerIntegratedAuth.cs
index d099656ac4..218b461b0a 100644
--- a/src/Hosting/Server.Abstractions/src/IServerIntegratedAuth.cs
+++ b/src/Hosting/Server.Abstractions/src/IServerIntegratedAuth.cs
@@ -16,6 +16,6 @@ namespace Microsoft.AspNetCore.Hosting.Server
///
/// The name of the authentication scheme for the server authentication handler.
///
- string AuthenticationScheme { get; }
+ string? AuthenticationScheme { get; }
}
}
diff --git a/src/Hosting/Server.Abstractions/src/Microsoft.AspNetCore.Hosting.Server.Abstractions.csproj b/src/Hosting/Server.Abstractions/src/Microsoft.AspNetCore.Hosting.Server.Abstractions.csproj
index 4e6c350a51..758bf3bff0 100644
--- a/src/Hosting/Server.Abstractions/src/Microsoft.AspNetCore.Hosting.Server.Abstractions.csproj
+++ b/src/Hosting/Server.Abstractions/src/Microsoft.AspNetCore.Hosting.Server.Abstractions.csproj
@@ -8,6 +8,7 @@
true
aspnetcore;hosting
false
+ enable
diff --git a/src/Hosting/Server.Abstractions/src/ServerIntegratedAuth.cs b/src/Hosting/Server.Abstractions/src/ServerIntegratedAuth.cs
index 93d9029913..0ab301cfaf 100644
--- a/src/Hosting/Server.Abstractions/src/ServerIntegratedAuth.cs
+++ b/src/Hosting/Server.Abstractions/src/ServerIntegratedAuth.cs
@@ -16,6 +16,6 @@ namespace Microsoft.AspNetCore.Hosting.Server
///
/// The name of the authentication scheme for the server authentication handler.
///
- public string AuthenticationScheme { get; set; }
+ public string? AuthenticationScheme { get; set; }
}
}
diff --git a/src/Hosting/build.cmd b/src/Hosting/build.cmd
new file mode 100644
index 0000000000..2406296662
--- /dev/null
+++ b/src/Hosting/build.cmd
@@ -0,0 +1,3 @@
+@ECHO OFF
+SET RepoRoot=%~dp0..\..
+%RepoRoot%\build.cmd -projects %~dp0**\*.*proj %*