diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs index 8fc1b8e43b..1d62b061dc 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting.Abstractions/HostingEnvironmentExtensions.cs @@ -3,7 +3,6 @@ using System; using System.IO; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Hosting { @@ -14,8 +13,13 @@ namespace Microsoft.AspNet.Hosting /// /// An instance of service. /// True if the environment name is Development, otherwise false. - public static bool IsDevelopment([NotNull]this IHostingEnvironment hostingEnvironment) + public static bool IsDevelopment(this IHostingEnvironment hostingEnvironment) { + if (hostingEnvironment == null) + { + throw new ArgumentNullException(nameof(hostingEnvironment)); + } + return hostingEnvironment.IsEnvironment(EnvironmentName.Development); } @@ -24,8 +28,13 @@ namespace Microsoft.AspNet.Hosting /// /// An instance of service. /// True if the environment name is Production, otherwise false. - public static bool IsProduction([NotNull]this IHostingEnvironment hostingEnvironment) + public static bool IsProduction(this IHostingEnvironment hostingEnvironment) { + if (hostingEnvironment == null) + { + throw new ArgumentNullException(nameof(hostingEnvironment)); + } + return hostingEnvironment.IsEnvironment(EnvironmentName.Production); } @@ -36,9 +45,14 @@ namespace Microsoft.AspNet.Hosting /// Environment name to validate against. /// True if the specified name is same as the current environment. public static bool IsEnvironment( - [NotNull]this IHostingEnvironment hostingEnvironment, + this IHostingEnvironment hostingEnvironment, string environmentName) { + if (hostingEnvironment == null) + { + throw new ArgumentNullException(nameof(hostingEnvironment)); + } + return string.Equals( hostingEnvironment.EnvironmentName, environmentName, @@ -52,9 +66,14 @@ namespace Microsoft.AspNet.Hosting /// Path relative to the root. /// Physical path corresponding to virtual path. public static string MapPath( - [NotNull]this IHostingEnvironment hostingEnvironment, + this IHostingEnvironment hostingEnvironment, string virtualPath) { + if (hostingEnvironment == null) + { + throw new ArgumentNullException(nameof(hostingEnvironment)); + } + if (virtualPath == null) { return hostingEnvironment.WebRootPath; diff --git a/src/Microsoft.AspNet.Hosting.Abstractions/project.json b/src/Microsoft.AspNet.Hosting.Abstractions/project.json index 6e143904ae..daaa329df3 100644 --- a/src/Microsoft.AspNet.Hosting.Abstractions/project.json +++ b/src/Microsoft.AspNet.Hosting.Abstractions/project.json @@ -7,8 +7,7 @@ }, "dependencies": { "Microsoft.AspNet.Http.Abstractions": "1.0.0-*", - "Microsoft.AspNet.FileProviders.Abstractions": "1.0.0-*", - "Microsoft.Framework.NotNullAttribute.Sources": { "type": "build", "version": "1.0.0-*" } + "Microsoft.AspNet.FileProviders.Abstractions": "1.0.0-*" }, "frameworks": { "dnx451": {}, diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index d072b36285..b57a218031 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -14,7 +14,6 @@ using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features.Internal; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Hosting.Internal @@ -39,10 +38,25 @@ namespace Microsoft.AspNet.Hosting.Internal private IFeatureCollection _serverInstance; public HostingEngine( - [NotNull] IServiceCollection appServices, - [NotNull] IStartupLoader startupLoader, - [NotNull] IConfiguration config) + IServiceCollection appServices, + IStartupLoader startupLoader, + IConfiguration config) { + if (appServices == null) + { + throw new ArgumentNullException(nameof(appServices)); + } + + if (startupLoader == null) + { + throw new ArgumentNullException(nameof(startupLoader)); + } + + if (config == null) + { + throw new ArgumentNullException(nameof(config)); + } + _config = config; _applicationServiceCollection = appServices; _startupLoader = startupLoader; diff --git a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs index 9c740ba7f1..ab3fda31ab 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerMiddleware.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Hosting.Internal { @@ -15,14 +14,29 @@ namespace Microsoft.AspNet.Hosting.Internal private readonly RequestDelegate _next; private readonly IServiceProvider _services; - public RequestServicesContainerMiddleware([NotNull] RequestDelegate next, [NotNull] IServiceProvider services) + public RequestServicesContainerMiddleware(RequestDelegate next, IServiceProvider services) { + if (next == null) + { + throw new ArgumentNullException(nameof(next)); + } + + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + _services = services; _next = next; } - public async Task Invoke([NotNull] HttpContext httpContext) + public async Task Invoke(HttpContext httpContext) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + // All done if there request services is set if (httpContext.RequestServices != null) { diff --git a/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs b/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs index 367f7bea05..3a94dfaca5 100644 --- a/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs @@ -5,7 +5,6 @@ using System; using System.Linq; using System.Reflection; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Hosting.Server { @@ -18,8 +17,13 @@ namespace Microsoft.AspNet.Hosting.Server _services = services; } - public IServerFactory LoadServerFactory([NotNull] string assemblyName) + public IServerFactory LoadServerFactory(string assemblyName) { + if (assemblyName == null) + { + throw new ArgumentNullException(nameof(assemblyName)); + } + if (string.IsNullOrEmpty(assemblyName)) { throw new ArgumentException(string.Empty, nameof(assemblyName)); diff --git a/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs b/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs index 977cb07238..716795bc8d 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/ConfigureServicesDelegate.cs @@ -5,14 +5,18 @@ using System; using System.Linq; using System.Reflection; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Hosting.Startup { public class ConfigureServicesBuilder { - public ConfigureServicesBuilder([NotNull] MethodInfo configureServices) + public ConfigureServicesBuilder(MethodInfo configureServices) { + if (configureServices == null) + { + throw new ArgumentNullException(nameof(configureServices)); + } + // Only support IServiceCollection parameters var parameters = configureServices.GetParameters(); if (parameters.Length > 1 || @@ -28,8 +32,13 @@ namespace Microsoft.AspNet.Hosting.Startup public Func Build(object instance) => services => Invoke(instance, services); - private IServiceProvider Invoke(object instance, [NotNull] IServiceCollection exportServices) + private IServiceProvider Invoke(object instance, IServiceCollection exportServices) { + if (exportServices == null) + { + throw new ArgumentNullException(nameof(exportServices)); + } + var parameters = new object[MethodInfo.GetParameters().Length]; // Ctor ensures we have at most one IServiceCollection parameter diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index 502d9bc09a..6efc8042d5 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -12,7 +12,6 @@ using Microsoft.AspNet.Http.Internal; using Microsoft.Dnx.Runtime; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Hosting @@ -44,13 +43,23 @@ namespace Microsoft.AspNet.Hosting private string _serverFactoryLocation; private IServerFactory _serverFactory; - public WebHostBuilder([NotNull] IServiceProvider services) + public WebHostBuilder(IServiceProvider services) : this(services, config: new ConfigurationBuilder().Build()) { } - public WebHostBuilder([NotNull] IServiceProvider services, [NotNull] IConfiguration config) + public WebHostBuilder(IServiceProvider services, IConfiguration config) { + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + + if (config == null) + { + throw new ArgumentNullException(nameof(config)); + } + _hostingEnvironment = new HostingEnvironment(); _loggerFactory = new LoggerFactory(); _services = services; @@ -124,14 +133,24 @@ namespace Microsoft.AspNet.Hosting return this; } - public WebHostBuilder UseEnvironment([NotNull] string environment) + public WebHostBuilder UseEnvironment(string environment) { + if (environment == null) + { + throw new ArgumentNullException(nameof(environment)); + } + _hostingEnvironment.EnvironmentName = environment; return this; } - public WebHostBuilder UseServer([NotNull] string assemblyName) + public WebHostBuilder UseServer(string assemblyName) { + if (assemblyName == null) + { + throw new ArgumentNullException(nameof(assemblyName)); + } + _serverFactoryLocation = assemblyName; return this; } @@ -142,22 +161,24 @@ namespace Microsoft.AspNet.Hosting return this; } - public WebHostBuilder UseStartup([NotNull] string startupAssemblyName) + public WebHostBuilder UseStartup(string startupAssemblyName) { if (startupAssemblyName == null) { throw new ArgumentNullException(nameof(startupAssemblyName)); } + _startupAssemblyName = startupAssemblyName; return this; } - public WebHostBuilder UseStartup([NotNull] Type startupType) + public WebHostBuilder UseStartup(Type startupType) { if (startupType == null) { throw new ArgumentNullException(nameof(startupType)); } + _startupType = startupType; return this; } @@ -167,19 +188,34 @@ namespace Microsoft.AspNet.Hosting return UseStartup(typeof(TStartup)); } - public WebHostBuilder UseStartup([NotNull] Action configureApp) + public WebHostBuilder UseStartup(Action configureApp) { + if (configureApp == null) + { + throw new ArgumentNullException(nameof(configureApp)); + } + return UseStartup(configureApp, configureServices: null); } - public WebHostBuilder UseStartup([NotNull] Action configureApp, Func configureServices) + public WebHostBuilder UseStartup(Action configureApp, Func configureServices) { + if (configureApp == null) + { + throw new ArgumentNullException(nameof(configureApp)); + } + _startup = new StartupMethods(configureApp, configureServices); return this; } - public WebHostBuilder UseStartup([NotNull] Action configureApp, Action configureServices) + public WebHostBuilder UseStartup(Action configureApp, Action configureServices) { + if (configureApp == null) + { + throw new ArgumentNullException(nameof(configureApp)); + } + _startup = new StartupMethods(configureApp, services => { diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index ad736ead8e..00218c9fb5 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -19,7 +19,6 @@ "Microsoft.Framework.DependencyInjection": "1.0.0-*", "Microsoft.Framework.Logging": "1.0.0-*", "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", - "Microsoft.Framework.NotNullAttribute.Sources": { "type": "build", "version": "1.0.0-*" }, "Newtonsoft.Json": "6.0.6" }, "frameworks": { diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index 12e03e8980..efcb5dc06e 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -14,7 +14,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Internal; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.TestHost { @@ -31,8 +30,13 @@ namespace Microsoft.AspNet.TestHost /// Create a new handler. /// /// The pipeline entry point. - public ClientHandler([NotNull] Func next, PathString pathBase) + public ClientHandler(Func next, PathString pathBase) { + if (next == null) + { + throw new ArgumentNullException(nameof(next)); + } + _next = next; // PathString.StartsWithSegments that we use below requires the base path to not end in a slash. @@ -51,9 +55,14 @@ namespace Microsoft.AspNet.TestHost /// /// protected override async Task SendAsync( - [NotNull] HttpRequestMessage request, + HttpRequestMessage request, CancellationToken cancellationToken) { + if (request == null) + { + throw new ArgumentNullException(nameof(request)); + } + var state = new RequestState(request, _pathBase); var requestContent = request.Content ?? new StreamContent(Stream.Null); var body = await requestContent.ReadAsStreamAsync(); diff --git a/src/Microsoft.AspNet.TestHost/RequestBuilder.cs b/src/Microsoft.AspNet.TestHost/RequestBuilder.cs index 3de390f63a..2de21ead03 100644 --- a/src/Microsoft.AspNet.TestHost/RequestBuilder.cs +++ b/src/Microsoft.AspNet.TestHost/RequestBuilder.cs @@ -3,11 +3,9 @@ using System; using System.Diagnostics.CodeAnalysis; -using System.Globalization; using System.IO; using System.Net.Http; using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.TestHost { @@ -27,8 +25,13 @@ namespace Microsoft.AspNet.TestHost /// /// [SuppressMessage("Microsoft.Usage", "CA2234:PassSystemUriObjectsInsteadOfStrings", Justification = "Not a full URI")] - public RequestBuilder([NotNull] TestServer server, string path) + public RequestBuilder(TestServer server, string path) { + if (server == null) + { + throw new ArgumentNullException(nameof(server)); + } + _server = server; _req = new HttpRequestMessage(HttpMethod.Get, path); } @@ -38,8 +41,13 @@ namespace Microsoft.AspNet.TestHost /// /// /// - public RequestBuilder And([NotNull] Action configure) + public RequestBuilder And(Action configure) { + if (configure == null) + { + throw new ArgumentNullException(nameof(configure)); + } + configure(_req); return this; } diff --git a/src/Microsoft.AspNet.TestHost/ResponseStream.cs b/src/Microsoft.AspNet.TestHost/ResponseStream.cs index 7f75c5983f..a1dd0df091 100644 --- a/src/Microsoft.AspNet.TestHost/ResponseStream.cs +++ b/src/Microsoft.AspNet.TestHost/ResponseStream.cs @@ -8,7 +8,6 @@ using System.Diagnostics.Contracts; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.TestHost { @@ -30,8 +29,18 @@ namespace Microsoft.AspNet.TestHost private bool _firstWrite; private Action _abortRequest; - internal ResponseStream([NotNull] Action onFirstWrite, [NotNull] Action abortRequest) + internal ResponseStream(Action onFirstWrite, Action abortRequest) { + if (onFirstWrite == null) + { + throw new ArgumentNullException(nameof(onFirstWrite)); + } + + if (abortRequest == null) + { + throw new ArgumentNullException(nameof(abortRequest)); + } + _onFirstWrite = onFirstWrite; _firstWrite = true; _abortRequest = abortRequest; diff --git a/src/Microsoft.AspNet.TestHost/WebSocketClient.cs b/src/Microsoft.AspNet.TestHost/WebSocketClient.cs index 1eaecbcb61..9946d5e4bd 100644 --- a/src/Microsoft.AspNet.TestHost/WebSocketClient.cs +++ b/src/Microsoft.AspNet.TestHost/WebSocketClient.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; @@ -11,7 +11,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Internal; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.TestHost { @@ -20,10 +19,15 @@ namespace Microsoft.AspNet.TestHost private readonly Func _next; private readonly PathString _pathBase; - internal WebSocketClient([NotNull] Func next, PathString pathBase) + internal WebSocketClient(Func next, PathString pathBase) { + if (next == null) + { + throw new ArgumentNullException(nameof(next)); + } + _next = next; - + // PathString.StartsWithSegments that we use below requires the base path to not end in a slash. if (pathBase.HasValue && pathBase.Value.EndsWith("/")) { diff --git a/src/Microsoft.AspNet.TestHost/project.json b/src/Microsoft.AspNet.TestHost/project.json index c59e21f29d..34769e53cd 100644 --- a/src/Microsoft.AspNet.TestHost/project.json +++ b/src/Microsoft.AspNet.TestHost/project.json @@ -6,8 +6,7 @@ "url": "git://github.com/aspnet/hosting" }, "dependencies": { - "Microsoft.AspNet.Hosting": "1.0.0-*", - "Microsoft.Framework.NotNullAttribute.Sources": { "version": "1.0.0-*", "type": "build" } + "Microsoft.AspNet.Hosting": "1.0.0-*" }, "frameworks": { "dnx451": { diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 5b9c50ba9a..1ded347dbb 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -413,7 +413,7 @@ namespace Microsoft.AspNet.Hosting private class ReadOnlyFeatureCollection : IFeatureCollection { - public object this[[NotNull] Type key] + public object this[Type key] { get { return null; } set { throw new NotSupportedException(); }