diff --git a/src/Microsoft.AspNet.StaticFiles/DefaultFilesExtensions.cs b/src/Microsoft.AspNet.StaticFiles/DefaultFilesExtensions.cs index 94c66210ef..29bebd7994 100644 --- a/src/Microsoft.AspNet.StaticFiles/DefaultFilesExtensions.cs +++ b/src/Microsoft.AspNet.StaticFiles/DefaultFilesExtensions.cs @@ -1,9 +1,9 @@ // 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; using Microsoft.AspNet.Http; using Microsoft.AspNet.StaticFiles; -using Microsoft.Extensions.Internal; namespace Microsoft.AspNet.Builder { @@ -17,8 +17,13 @@ namespace Microsoft.AspNet.Builder /// /// /// - public static IApplicationBuilder UseDefaultFiles([NotNull] this IApplicationBuilder builder) + public static IApplicationBuilder UseDefaultFiles(this IApplicationBuilder builder) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + return builder.UseDefaultFiles(new DefaultFilesOptions()); } @@ -28,8 +33,13 @@ namespace Microsoft.AspNet.Builder /// /// The relative request path. /// - public static IApplicationBuilder UseDefaultFiles([NotNull] this IApplicationBuilder builder, [NotNull] string requestPath) + public static IApplicationBuilder UseDefaultFiles(this IApplicationBuilder builder, string requestPath) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + return builder.UseDefaultFiles(new DefaultFilesOptions() { RequestPath = new PathString(requestPath) }); } @@ -39,8 +49,18 @@ namespace Microsoft.AspNet.Builder /// /// /// - public static IApplicationBuilder UseDefaultFiles([NotNull] this IApplicationBuilder builder, [NotNull] DefaultFilesOptions options) + public static IApplicationBuilder UseDefaultFiles(this IApplicationBuilder builder, DefaultFilesOptions options) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + return builder.UseMiddleware(options); } } diff --git a/src/Microsoft.AspNet.StaticFiles/DefaultFilesMiddleware.cs b/src/Microsoft.AspNet.StaticFiles/DefaultFilesMiddleware.cs index 492d8e379c..4bba12af68 100644 --- a/src/Microsoft.AspNet.StaticFiles/DefaultFilesMiddleware.cs +++ b/src/Microsoft.AspNet.StaticFiles/DefaultFilesMiddleware.cs @@ -1,11 +1,11 @@ // 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; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; -using Microsoft.Extensions.Internal; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNet.StaticFiles @@ -26,8 +26,23 @@ namespace Microsoft.AspNet.StaticFiles /// /// The next middleware in the pipeline. /// The configuration options for this middleware. - public DefaultFilesMiddleware([NotNull] RequestDelegate next, [NotNull] IHostingEnvironment hostingEnv, [NotNull] DefaultFilesOptions options) + public DefaultFilesMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, DefaultFilesOptions options) { + if (next == null) + { + throw new ArgumentNullException(nameof(next)); + } + + if (hostingEnv == null) + { + throw new ArgumentNullException(nameof(hostingEnv)); + } + + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + options.ResolveFileProvider(hostingEnv); _next = next; diff --git a/src/Microsoft.AspNet.StaticFiles/DirectoryBrowserExtensions.cs b/src/Microsoft.AspNet.StaticFiles/DirectoryBrowserExtensions.cs index 3b2537a8d9..01539129cb 100644 --- a/src/Microsoft.AspNet.StaticFiles/DirectoryBrowserExtensions.cs +++ b/src/Microsoft.AspNet.StaticFiles/DirectoryBrowserExtensions.cs @@ -1,9 +1,9 @@ // 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; using Microsoft.AspNet.Http; using Microsoft.AspNet.StaticFiles; -using Microsoft.Extensions.Internal; namespace Microsoft.AspNet.Builder { @@ -17,8 +17,13 @@ namespace Microsoft.AspNet.Builder /// /// /// - public static IApplicationBuilder UseDirectoryBrowser([NotNull] this IApplicationBuilder builder) + public static IApplicationBuilder UseDirectoryBrowser(this IApplicationBuilder builder) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + return builder.UseDirectoryBrowser(new DirectoryBrowserOptions()); } @@ -28,8 +33,13 @@ namespace Microsoft.AspNet.Builder /// /// The relative request path. /// - public static IApplicationBuilder UseDirectoryBrowser([NotNull] this IApplicationBuilder builder, [NotNull] string requestPath) + public static IApplicationBuilder UseDirectoryBrowser(this IApplicationBuilder builder, string requestPath) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + return builder.UseDirectoryBrowser(new DirectoryBrowserOptions() { RequestPath = new PathString(requestPath) }); } @@ -39,8 +49,18 @@ namespace Microsoft.AspNet.Builder /// /// /// - public static IApplicationBuilder UseDirectoryBrowser([NotNull] this IApplicationBuilder builder, [NotNull] DirectoryBrowserOptions options) + public static IApplicationBuilder UseDirectoryBrowser(this IApplicationBuilder builder, DirectoryBrowserOptions options) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + return builder.UseMiddleware(options); } } diff --git a/src/Microsoft.AspNet.StaticFiles/DirectoryBrowserMiddleware.cs b/src/Microsoft.AspNet.StaticFiles/DirectoryBrowserMiddleware.cs index d9b0f450cb..dbb2eb2aef 100644 --- a/src/Microsoft.AspNet.StaticFiles/DirectoryBrowserMiddleware.cs +++ b/src/Microsoft.AspNet.StaticFiles/DirectoryBrowserMiddleware.cs @@ -7,7 +7,6 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; -using Microsoft.Extensions.Internal; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNet.StaticFiles @@ -26,8 +25,23 @@ namespace Microsoft.AspNet.StaticFiles /// /// The next middleware in the pipeline. /// The configuration for this middleware. - public DirectoryBrowserMiddleware([NotNull] RequestDelegate next, [NotNull] IHostingEnvironment hostingEnv, [NotNull] DirectoryBrowserOptions options) + public DirectoryBrowserMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, DirectoryBrowserOptions options) { + if (next == null) + { + throw new ArgumentNullException(nameof(next)); + } + + if (hostingEnv == null) + { + throw new ArgumentNullException(nameof(hostingEnv)); + } + + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + if (options.Formatter == null) { throw new ArgumentException(Resources.Args_NoFormatter); diff --git a/src/Microsoft.AspNet.StaticFiles/DirectoryBrowserServiceExtensions.cs b/src/Microsoft.AspNet.StaticFiles/DirectoryBrowserServiceExtensions.cs index 1eaa7674d0..258358a04a 100644 --- a/src/Microsoft.AspNet.StaticFiles/DirectoryBrowserServiceExtensions.cs +++ b/src/Microsoft.AspNet.StaticFiles/DirectoryBrowserServiceExtensions.cs @@ -1,8 +1,7 @@ // 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 Microsoft.Extensions.Internal; -using Microsoft.AspNet.StaticFiles; +using System; namespace Microsoft.Extensions.DependencyInjection { @@ -16,8 +15,13 @@ namespace Microsoft.Extensions.DependencyInjection /// /// /// - public static IServiceCollection AddDirectoryBrowser([NotNull] this IServiceCollection services) + public static IServiceCollection AddDirectoryBrowser(this IServiceCollection services) { + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + return services.AddWebEncoders(); } } diff --git a/src/Microsoft.AspNet.StaticFiles/FileServerExtensions.cs b/src/Microsoft.AspNet.StaticFiles/FileServerExtensions.cs index c286144de7..4b97459f50 100644 --- a/src/Microsoft.AspNet.StaticFiles/FileServerExtensions.cs +++ b/src/Microsoft.AspNet.StaticFiles/FileServerExtensions.cs @@ -4,7 +4,6 @@ using System; using Microsoft.AspNet.Http; using Microsoft.AspNet.StaticFiles; -using Microsoft.Extensions.Internal; namespace Microsoft.AspNet.Builder { @@ -19,8 +18,13 @@ namespace Microsoft.AspNet.Builder /// /// /// - public static IApplicationBuilder UseFileServer([NotNull] this IApplicationBuilder builder) + public static IApplicationBuilder UseFileServer(this IApplicationBuilder builder) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + return builder.UseFileServer(new FileServerOptions()); } @@ -30,8 +34,13 @@ namespace Microsoft.AspNet.Builder /// /// Should directory browsing be enabled? /// - public static IApplicationBuilder UseFileServer([NotNull] this IApplicationBuilder builder, bool enableDirectoryBrowsing) + public static IApplicationBuilder UseFileServer(this IApplicationBuilder builder, bool enableDirectoryBrowsing) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + return builder.UseFileServer(new FileServerOptions() { EnableDirectoryBrowsing = enableDirectoryBrowsing }); } @@ -41,8 +50,18 @@ namespace Microsoft.AspNet.Builder /// /// The relative request path. /// - public static IApplicationBuilder UseFileServer([NotNull] this IApplicationBuilder builder, [NotNull] string requestPath) + public static IApplicationBuilder UseFileServer(this IApplicationBuilder builder, string requestPath) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (requestPath == null) + { + throw new ArgumentNullException(nameof(requestPath)); + } + return builder.UseFileServer(new FileServerOptions() { RequestPath = new PathString(requestPath) }); } @@ -52,8 +71,18 @@ namespace Microsoft.AspNet.Builder /// /// /// - public static IApplicationBuilder UseFileServer([NotNull] this IApplicationBuilder builder, [NotNull] FileServerOptions options) + public static IApplicationBuilder UseFileServer(this IApplicationBuilder builder, FileServerOptions options) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + if (options == null) { throw new ArgumentNullException(nameof(options)); diff --git a/src/Microsoft.AspNet.StaticFiles/SendFileExtensions.cs b/src/Microsoft.AspNet.StaticFiles/SendFileExtensions.cs index 00b5ac8f25..f6a5d287d6 100644 --- a/src/Microsoft.AspNet.StaticFiles/SendFileExtensions.cs +++ b/src/Microsoft.AspNet.StaticFiles/SendFileExtensions.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using Microsoft.AspNet.Builder; -using Microsoft.Extensions.Internal; namespace Microsoft.AspNet.StaticFiles { @@ -18,8 +17,13 @@ namespace Microsoft.AspNet.StaticFiles /// /// /// - public static IApplicationBuilder UseSendFileFallback([NotNull] this IApplicationBuilder builder) + public static IApplicationBuilder UseSendFileFallback(this IApplicationBuilder builder) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + /* TODO builder.GetItem(typeof(ISendFile)) // Check for advertised support diff --git a/src/Microsoft.AspNet.StaticFiles/SendFileMiddleware.cs b/src/Microsoft.AspNet.StaticFiles/SendFileMiddleware.cs index 0995ad86b8..c642a1eb39 100644 --- a/src/Microsoft.AspNet.StaticFiles/SendFileMiddleware.cs +++ b/src/Microsoft.AspNet.StaticFiles/SendFileMiddleware.cs @@ -8,7 +8,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; -using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.StaticFiles @@ -29,8 +28,18 @@ namespace Microsoft.AspNet.StaticFiles /// /// The next middleware in the pipeline. /// An instance used to create loggers. - public SendFileMiddleware([NotNull] RequestDelegate next, [NotNull] ILoggerFactory loggerFactory) + public SendFileMiddleware(RequestDelegate next, ILoggerFactory loggerFactory) { + if (next == null) + { + throw new ArgumentNullException(nameof(next)); + } + + if (loggerFactory == null) + { + throw new ArgumentNullException(nameof(loggerFactory)); + } + _next = next; _logger = loggerFactory.CreateLogger(); } diff --git a/src/Microsoft.AspNet.StaticFiles/StaticFileExtensions.cs b/src/Microsoft.AspNet.StaticFiles/StaticFileExtensions.cs index ff2257723e..a1912f5bad 100644 --- a/src/Microsoft.AspNet.StaticFiles/StaticFileExtensions.cs +++ b/src/Microsoft.AspNet.StaticFiles/StaticFileExtensions.cs @@ -1,9 +1,9 @@ // 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; using Microsoft.AspNet.Http; using Microsoft.AspNet.StaticFiles; -using Microsoft.Extensions.Internal; namespace Microsoft.AspNet.Builder { @@ -17,8 +17,13 @@ namespace Microsoft.AspNet.Builder /// /// /// - public static IApplicationBuilder UseStaticFiles([NotNull] this IApplicationBuilder builder) + public static IApplicationBuilder UseStaticFiles(this IApplicationBuilder builder) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + return builder.UseStaticFiles(new StaticFileOptions()); } @@ -28,8 +33,13 @@ namespace Microsoft.AspNet.Builder /// /// The relative request path. /// - public static IApplicationBuilder UseStaticFiles([NotNull] this IApplicationBuilder builder, [NotNull] string requestPath) + public static IApplicationBuilder UseStaticFiles(this IApplicationBuilder builder, string requestPath) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + return builder.UseStaticFiles(new StaticFileOptions() { RequestPath = new PathString(requestPath) }); } @@ -39,8 +49,18 @@ namespace Microsoft.AspNet.Builder /// /// /// - public static IApplicationBuilder UseStaticFiles([NotNull] this IApplicationBuilder builder, [NotNull] StaticFileOptions options) + public static IApplicationBuilder UseStaticFiles(this IApplicationBuilder builder, StaticFileOptions options) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + return builder.UseMiddleware(options); } } diff --git a/src/Microsoft.AspNet.StaticFiles/StaticFileMiddleware.cs b/src/Microsoft.AspNet.StaticFiles/StaticFileMiddleware.cs index fad669b095..c5d42b545c 100644 --- a/src/Microsoft.AspNet.StaticFiles/StaticFileMiddleware.cs +++ b/src/Microsoft.AspNet.StaticFiles/StaticFileMiddleware.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; -using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.StaticFiles @@ -27,8 +26,28 @@ namespace Microsoft.AspNet.StaticFiles /// The next middleware in the pipeline. /// The configuration options. /// An instance used to create loggers. - public StaticFileMiddleware([NotNull] RequestDelegate next, [NotNull] IHostingEnvironment hostingEnv, [NotNull] StaticFileOptions options, [NotNull] ILoggerFactory loggerFactory) + public StaticFileMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, StaticFileOptions options, ILoggerFactory loggerFactory) { + if (next == null) + { + throw new ArgumentNullException(nameof(next)); + } + + if (hostingEnv == null) + { + throw new ArgumentNullException(nameof(hostingEnv)); + } + + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + + if (loggerFactory == null) + { + throw new ArgumentNullException(nameof(loggerFactory)); + } + if (options.ContentTypeProvider == null) { throw new ArgumentException(Resources.Args_NoContentTypeProvider); diff --git a/src/Microsoft.AspNet.StaticFiles/project.json b/src/Microsoft.AspNet.StaticFiles/project.json index 7f84cb2fc7..52f19a518e 100644 --- a/src/Microsoft.AspNet.StaticFiles/project.json +++ b/src/Microsoft.AspNet.StaticFiles/project.json @@ -10,7 +10,6 @@ "Microsoft.AspNet.FileProviders.Abstractions": "1.0.0-*", "Microsoft.AspNet.Hosting.Abstractions": "1.0.0-*", "Microsoft.Extensions.Logging.Abstractions": "1.0.0-*", - "Microsoft.Extensions.NotNullAttribute.Sources": { "type": "build", "version": "1.0.0-*" }, "Microsoft.Extensions.WebEncoders": "1.0.0-*" }, "frameworks": {