diff --git a/src/Microsoft.AspNet.Diagnostics.Elm/ElmExtensions.cs b/src/Microsoft.AspNet.Diagnostics.Elm/ElmExtensions.cs
index 606a8183a9..3774baf3cf 100644
--- a/src/Microsoft.AspNet.Diagnostics.Elm/ElmExtensions.cs
+++ b/src/Microsoft.AspNet.Diagnostics.Elm/ElmExtensions.cs
@@ -14,33 +14,33 @@ namespace Microsoft.AspNet.Builder
///
/// Enables the Elm logging service, which can be accessed via the .
///
- public static IApplicationBuilder UseElmCapture(this IApplicationBuilder builder)
+ public static IApplicationBuilder UseElmCapture(this IApplicationBuilder app)
{
- if (builder == null)
+ if (app == null)
{
- throw new ArgumentNullException(nameof(builder));
+ throw new ArgumentNullException(nameof(app));
}
// add the elm provider to the factory here so the logger can start capturing logs immediately
- var factory = builder.ApplicationServices.GetRequiredService();
- var store = builder.ApplicationServices.GetRequiredService();
- var options = builder.ApplicationServices.GetService>();
+ var factory = app.ApplicationServices.GetRequiredService();
+ var store = app.ApplicationServices.GetRequiredService();
+ var options = app.ApplicationServices.GetService>();
factory.AddProvider(new ElmLoggerProvider(store, options?.Value ?? new ElmOptions()));
- return builder.UseMiddleware();
+ return app.UseMiddleware();
}
///
/// Enables viewing logs captured by the .
///
- public static IApplicationBuilder UseElmPage(this IApplicationBuilder builder)
+ public static IApplicationBuilder UseElmPage(this IApplicationBuilder app)
{
- if (builder == null)
+ if (app == null)
{
- throw new ArgumentNullException(nameof(builder));
+ throw new ArgumentNullException(nameof(app));
}
- return builder.UseMiddleware();
+ return app.UseMiddleware();
}
}
}
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.Diagnostics.Entity/DatabaseErrorPageExtensions.cs b/src/Microsoft.AspNet.Diagnostics.Entity/DatabaseErrorPageExtensions.cs
index 4ca7f0bf43..d4763eeb71 100644
--- a/src/Microsoft.AspNet.Diagnostics.Entity/DatabaseErrorPageExtensions.cs
+++ b/src/Microsoft.AspNet.Diagnostics.Entity/DatabaseErrorPageExtensions.cs
@@ -20,9 +20,12 @@ namespace Microsoft.AspNet.Builder
///
/// The to register the middleware with.
/// The same instance so that multiple calls can be chained.
- public static IApplicationBuilder UseDatabaseErrorPage([NotNull] this IApplicationBuilder app)
+ public static IApplicationBuilder UseDatabaseErrorPage(this IApplicationBuilder app)
{
- Check.NotNull(app, nameof(app));
+ if (app == null)
+ {
+ throw new ArgumentNullException(nameof(app));
+ }
return app.UseDatabaseErrorPage(options => options.EnableAll());
}
@@ -32,19 +35,25 @@ namespace Microsoft.AspNet.Builder
/// migrations. When these exceptions occur an HTML response with details of possible actions to resolve the issue is generated.
///
/// The to register the middleware with.
- /// An action to set the options for the middleware. All options are disabled by default.
+ /// An action to set the options for the middleware. All options are disabled by default.
/// The same instance so that multiple calls can be chained.
- public static IApplicationBuilder UseDatabaseErrorPage([NotNull] this IApplicationBuilder app, [NotNull] Action optionsAction)
+ public static IApplicationBuilder UseDatabaseErrorPage(this IApplicationBuilder app, Action configureOptions)
{
- Check.NotNull(app, nameof(app));
- Check.NotNull(optionsAction, nameof(optionsAction));
+ if (app == null)
+ {
+ throw new ArgumentNullException(nameof(app));
+ }
+ if (configureOptions == null)
+ {
+ throw new ArgumentNullException(nameof(configureOptions));
+ }
var options = new DatabaseErrorPageOptions();
- optionsAction(options);
+ configureOptions(options);
app = app.UseMiddleware(options);
- if(options.EnableMigrationCommands)
+ if (options.EnableMigrationCommands)
{
app.UseMigrationsEndPoint(o => o.Path = options.MigrationsEndPointPath);
}
@@ -56,9 +65,12 @@ namespace Microsoft.AspNet.Builder
/// Sets the options to display the maximum amount of information available.
///
/// The options to be configured.
- public static void EnableAll([NotNull] this DatabaseErrorPageOptions options)
+ public static void EnableAll(this DatabaseErrorPageOptions options)
{
- Check.NotNull(options, nameof(options));
+ if (options == null)
+ {
+ throw new ArgumentNullException(nameof(options));
+ }
options.ShowExceptionDetails = true;
options.ListMigrations = true;
diff --git a/src/Microsoft.AspNet.Diagnostics.Entity/MigrationsEndPointExtensions.cs b/src/Microsoft.AspNet.Diagnostics.Entity/MigrationsEndPointExtensions.cs
index 0467cb5d22..d34aea8b43 100644
--- a/src/Microsoft.AspNet.Diagnostics.Entity/MigrationsEndPointExtensions.cs
+++ b/src/Microsoft.AspNet.Diagnostics.Entity/MigrationsEndPointExtensions.cs
@@ -18,26 +18,30 @@ namespace Microsoft.AspNet.Builder
///
/// The to register the middleware with.
/// The same instance so that multiple calls can be chained.
- public static IApplicationBuilder UseMigrationsEndPoint([NotNull] this IApplicationBuilder app)
+ public static IApplicationBuilder UseMigrationsEndPoint(this IApplicationBuilder app)
{
- Check.NotNull(app, "builder");
-
return app.UseMigrationsEndPoint(options => { });
}
///
- /// Processes requests to execute migrations operations. The middleware will listen for requests to the path configured in .
+ /// Processes requests to execute migrations operations. The middleware will listen for requests to the path configured in .
///
/// The to register the middleware with.
- /// An action to set the options for the middleware.
+ /// An action to set the options for the middleware.
/// The same instance so that multiple calls can be chained.
- public static IApplicationBuilder UseMigrationsEndPoint([NotNull] this IApplicationBuilder app, [NotNull] Action optionsAction)
+ public static IApplicationBuilder UseMigrationsEndPoint(this IApplicationBuilder app, Action configureOptions)
{
- Check.NotNull(app, "builder");
- Check.NotNull(optionsAction, "optionsAction");
+ if (app == null)
+ {
+ throw new ArgumentNullException(nameof(app));
+ }
+ if (configureOptions == null)
+ {
+ throw new ArgumentNullException(nameof(configureOptions));
+ }
var options = new MigrationsEndPointOptions();
- optionsAction(options);
+ configureOptions(options);
return app.UseMiddleware(options);
}
diff --git a/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/DeveloperExceptionPageExtensions.cs b/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/DeveloperExceptionPageExtensions.cs
index 28d652cb50..f895173ad6 100644
--- a/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/DeveloperExceptionPageExtensions.cs
+++ b/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/DeveloperExceptionPageExtensions.cs
@@ -14,31 +14,31 @@ namespace Microsoft.AspNet.Builder
///
/// Captures synchronous and asynchronous instances from the pipeline and generates HTML error responses.
///
- /// The .
- /// A reference to the after the operation has completed.
- public static IApplicationBuilder UseDeveloperExceptionPage(this IApplicationBuilder builder)
+ /// The .
+ /// A reference to the after the operation has completed.
+ public static IApplicationBuilder UseDeveloperExceptionPage(this IApplicationBuilder app)
{
- if (builder == null)
+ if (app == null)
{
- throw new ArgumentNullException(nameof(builder));
+ throw new ArgumentNullException(nameof(app));
}
- return builder.UseDeveloperExceptionPage(options => { });
+ return app.UseDeveloperExceptionPage(options => { });
}
///
/// Captures synchronous and asynchronous instances from the pipeline and generates HTML error responses.
///
- /// The .
+ /// The .
/// A callback to configure .
- /// A reference to the after the operation has completed.
+ /// A reference to the after the operation has completed.
public static IApplicationBuilder UseDeveloperExceptionPage(
- this IApplicationBuilder builder,
+ this IApplicationBuilder app,
Action configureOptions)
{
- if (builder == null)
+ if (app == null)
{
- throw new ArgumentNullException(nameof(builder));
+ throw new ArgumentNullException(nameof(app));
}
if (configureOptions == null)
@@ -48,7 +48,7 @@ namespace Microsoft.AspNet.Builder
var options = new DeveloperExceptionPageOptions();
configureOptions(options);
- return builder.UseMiddleware(options);
+ return app.UseMiddleware(options);
}
}
}
diff --git a/src/Microsoft.AspNet.Diagnostics/ExceptionHandler/ExceptionHandlerExtensions.cs b/src/Microsoft.AspNet.Diagnostics/ExceptionHandler/ExceptionHandlerExtensions.cs
index 4fb98ec834..f852fe8ad6 100644
--- a/src/Microsoft.AspNet.Diagnostics/ExceptionHandler/ExceptionHandlerExtensions.cs
+++ b/src/Microsoft.AspNet.Diagnostics/ExceptionHandler/ExceptionHandlerExtensions.cs
@@ -18,11 +18,12 @@ namespace Microsoft.AspNet.Builder
///
public static IApplicationBuilder UseExceptionHandler(this IApplicationBuilder app, string errorHandlingPath)
{
- var options = new ExceptionHandlerOptions()
+ if (app == null)
{
- ExceptionHandlingPath = new PathString(errorHandlingPath)
- };
- return app.UseMiddleware(options);
+ throw new ArgumentNullException(nameof(app));
+ }
+
+ return app.UseExceptionHandler(options => { options.ExceptionHandlingPath = new PathString(errorHandlingPath); });
}
///
@@ -34,13 +35,43 @@ namespace Microsoft.AspNet.Builder
///
public static IApplicationBuilder UseExceptionHandler(this IApplicationBuilder app, Action configure)
{
+ if (app == null)
+ {
+ throw new ArgumentNullException(nameof(app));
+ }
+ if (configure == null)
+ {
+ throw new ArgumentNullException(nameof(configure));
+ }
+
var subAppBuilder = app.New();
configure(subAppBuilder);
var exceptionHandlerPipeline = subAppBuilder.Build();
- var options = new ExceptionHandlerOptions()
+
+ return app.UseExceptionHandler(options => { options.ExceptionHandler = exceptionHandlerPipeline; });
+ }
+
+ ///
+ /// Adds a middleware to the pipeline that will catch exceptions, log them, and re-execute the request in an alternate pipeline.
+ /// The request will not be re-executed if the response has already started.
+ ///
+ ///
+ ///
+ ///
+ public static IApplicationBuilder UseExceptionHandler(this IApplicationBuilder app, Action configureOptions)
+ {
+ if (app == null)
{
- ExceptionHandler = exceptionHandlerPipeline
- };
+ throw new ArgumentNullException(nameof(app));
+ }
+ if (configureOptions == null)
+ {
+ throw new ArgumentNullException(nameof(configureOptions));
+ }
+
+ var options = new ExceptionHandlerOptions();
+ configureOptions(options);
+
return app.UseMiddleware(options);
}
}
diff --git a/src/Microsoft.AspNet.Diagnostics/ExceptionHandler/ExceptionHandlerOptions.cs b/src/Microsoft.AspNet.Diagnostics/ExceptionHandler/ExceptionHandlerOptions.cs
index eae58731fc..2eedfb2b38 100644
--- a/src/Microsoft.AspNet.Diagnostics/ExceptionHandler/ExceptionHandlerOptions.cs
+++ b/src/Microsoft.AspNet.Diagnostics/ExceptionHandler/ExceptionHandlerOptions.cs
@@ -1,7 +1,6 @@
// 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.AspNet.Builder;
using Microsoft.AspNet.Http;
namespace Microsoft.AspNet.Diagnostics
diff --git a/src/Microsoft.AspNet.Diagnostics/RuntimeInfo/RuntimeInfoExtensions.cs b/src/Microsoft.AspNet.Diagnostics/RuntimeInfo/RuntimeInfoExtensions.cs
index f439c29c05..524c42f6cf 100644
--- a/src/Microsoft.AspNet.Diagnostics/RuntimeInfo/RuntimeInfoExtensions.cs
+++ b/src/Microsoft.AspNet.Diagnostics/RuntimeInfo/RuntimeInfoExtensions.cs
@@ -10,33 +10,45 @@ namespace Microsoft.AspNet.Builder
{
public static class RuntimeInfoExtensions
{
- public static IApplicationBuilder UseRuntimeInfoPage(this IApplicationBuilder builder)
+ public static IApplicationBuilder UseRuntimeInfoPage(this IApplicationBuilder app)
{
- return UseRuntimeInfoPage(builder, new RuntimeInfoPageOptions());
+ if (app == null)
+ {
+ throw new ArgumentNullException(nameof(app));
+ }
+
+ return app.UseRuntimeInfoPage(options => { });
}
- public static IApplicationBuilder UseRuntimeInfoPage(this IApplicationBuilder builder, string path)
+ public static IApplicationBuilder UseRuntimeInfoPage(this IApplicationBuilder app, string path)
{
- return UseRuntimeInfoPage(builder, new RuntimeInfoPageOptions() { Path = new PathString(path) });
+ if (app == null)
+ {
+ throw new ArgumentNullException(nameof(app));
+ }
+
+ return app.UseRuntimeInfoPage(options => { options.Path = new PathString(path); });
}
public static IApplicationBuilder UseRuntimeInfoPage(
- this IApplicationBuilder builder,
- RuntimeInfoPageOptions options)
+ this IApplicationBuilder app,
+ Action configureOptions)
{
- if (builder == null)
+ if (app == null)
{
- throw new ArgumentNullException(nameof(builder));
+ throw new ArgumentNullException(nameof(app));
+ }
+ if (configureOptions == null)
+ {
+ throw new ArgumentNullException(nameof(configureOptions));
}
- if (options == null)
- {
- throw new ArgumentNullException(nameof(options));
- }
+ var libraryManager = app.ApplicationServices.GetService(typeof(ILibraryManager)) as ILibraryManager;
+ var runtimeEnvironment = app.ApplicationServices.GetService(typeof(IRuntimeEnvironment)) as IRuntimeEnvironment;
+ var options = new RuntimeInfoPageOptions();
+ configureOptions(options);
- var libraryManager = builder.ApplicationServices.GetService(typeof(ILibraryManager)) as ILibraryManager;
- var runtimeEnvironment = builder.ApplicationServices.GetService(typeof(IRuntimeEnvironment)) as IRuntimeEnvironment;
- return builder.Use(next => new RuntimeInfoMiddleware(next, options, libraryManager, runtimeEnvironment).Invoke);
+ return app.Use(next => new RuntimeInfoMiddleware(next, options, libraryManager, runtimeEnvironment).Invoke);
}
}
}
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.Diagnostics/StatusCodePage/StatusCodePagesExtensions.cs b/src/Microsoft.AspNet.Diagnostics/StatusCodePage/StatusCodePagesExtensions.cs
index c2b92caf3c..176116fedc 100644
--- a/src/Microsoft.AspNet.Diagnostics/StatusCodePage/StatusCodePagesExtensions.cs
+++ b/src/Microsoft.AspNet.Diagnostics/StatusCodePage/StatusCodePagesExtensions.cs
@@ -17,14 +17,21 @@ namespace Microsoft.AspNet.Builder
/// between 400 and 599 that do not have a body.
///
///
- ///
+ ///
///
- public static IApplicationBuilder UseStatusCodePages(this IApplicationBuilder app, StatusCodePagesOptions options)
+ public static IApplicationBuilder UseStatusCodePages(this IApplicationBuilder app, Action configureOptions)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
+ if (configureOptions == null)
+ {
+ throw new ArgumentNullException(nameof(configureOptions));
+ }
+
+ var options = new StatusCodePagesOptions();
+ configureOptions(options);
return app.UseMiddleware(options);
}
@@ -37,7 +44,12 @@ namespace Microsoft.AspNet.Builder
///
public static IApplicationBuilder UseStatusCodePages(this IApplicationBuilder app)
{
- return UseStatusCodePages(app, new StatusCodePagesOptions());
+ if (app == null)
+ {
+ throw new ArgumentNullException(nameof(app));
+ }
+
+ return app.UseStatusCodePages(configureOptions: options => { });
}
///
@@ -49,7 +61,16 @@ namespace Microsoft.AspNet.Builder
///
public static IApplicationBuilder UseStatusCodePages(this IApplicationBuilder app, Func handler)
{
- return UseStatusCodePages(app, new StatusCodePagesOptions() { HandleAsync = handler });
+ if (app == null)
+ {
+ throw new ArgumentNullException(nameof(app));
+ }
+ if (handler == null)
+ {
+ throw new ArgumentNullException(nameof(handler));
+ }
+
+ return app.UseStatusCodePages(options => { options.HandleAsync = handler; });
}
///
@@ -62,7 +83,12 @@ namespace Microsoft.AspNet.Builder
///
public static IApplicationBuilder UseStatusCodePages(this IApplicationBuilder app, string contentType, string bodyFormat)
{
- return UseStatusCodePages(app, context =>
+ if (app == null)
+ {
+ throw new ArgumentNullException(nameof(app));
+ }
+
+ return app.UseStatusCodePages(context =>
{
var body = string.Format(CultureInfo.InvariantCulture, bodyFormat, context.HttpContext.Response.StatusCode);
context.HttpContext.Response.ContentType = contentType;
@@ -80,10 +106,15 @@ namespace Microsoft.AspNet.Builder
///
public static IApplicationBuilder UseStatusCodePagesWithRedirects(this IApplicationBuilder app, string locationFormat)
{
+ if (app == null)
+ {
+ throw new ArgumentNullException(nameof(app));
+ }
+
if (locationFormat.StartsWith("~"))
{
locationFormat = locationFormat.Substring(1);
- return UseStatusCodePages(app, context =>
+ return app.UseStatusCodePages(context =>
{
var location = string.Format(CultureInfo.InvariantCulture, locationFormat, context.HttpContext.Response.StatusCode);
context.HttpContext.Response.Redirect(context.HttpContext.Request.PathBase + location);
@@ -92,7 +123,7 @@ namespace Microsoft.AspNet.Builder
}
else
{
- return UseStatusCodePages(app, context =>
+ return app.UseStatusCodePages(context =>
{
var location = string.Format(CultureInfo.InvariantCulture, locationFormat, context.HttpContext.Response.StatusCode);
context.HttpContext.Response.Redirect(location);
@@ -110,10 +141,15 @@ namespace Microsoft.AspNet.Builder
///
public static IApplicationBuilder UseStatusCodePages(this IApplicationBuilder app, Action configuration)
{
+ if (app == null)
+ {
+ throw new ArgumentNullException(nameof(app));
+ }
+
var builder = app.New();
configuration(builder);
var tangent = builder.Build();
- return UseStatusCodePages(app, context => tangent(context.HttpContext));
+ return app.UseStatusCodePages(context => tangent(context.HttpContext));
}
///
@@ -125,7 +161,12 @@ namespace Microsoft.AspNet.Builder
///
public static IApplicationBuilder UseStatusCodePagesWithReExecute(this IApplicationBuilder app, string pathFormat)
{
- return UseStatusCodePages(app, async context =>
+ if (app == null)
+ {
+ throw new ArgumentNullException(nameof(app));
+ }
+
+ return app.UseStatusCodePages(async context =>
{
var newPath = new PathString(string.Format(CultureInfo.InvariantCulture, pathFormat, context.HttpContext.Response.StatusCode));
diff --git a/src/Microsoft.AspNet.Diagnostics/WelcomePage/WelcomePageExtensions.cs b/src/Microsoft.AspNet.Diagnostics/WelcomePage/WelcomePageExtensions.cs
index 43eb166ea6..478f342b3f 100644
--- a/src/Microsoft.AspNet.Diagnostics/WelcomePage/WelcomePageExtensions.cs
+++ b/src/Microsoft.AspNet.Diagnostics/WelcomePage/WelcomePageExtensions.cs
@@ -16,49 +16,71 @@ namespace Microsoft.AspNet.Builder
///
/// Adds the WelcomePageMiddleware to the pipeline with the given options.
///
- ///
- ///
+ ///
+ ///
///
- public static IApplicationBuilder UseWelcomePage(this IApplicationBuilder builder, WelcomePageOptions options)
+ public static IApplicationBuilder UseWelcomePage(this IApplicationBuilder app, Action configureOptions)
{
- if (builder == null)
+ if (app == null)
{
- throw new ArgumentNullException(nameof(builder));
+ throw new ArgumentNullException(nameof(app));
+ }
+ if (configureOptions == null)
+ {
+ throw new ArgumentNullException(nameof(configureOptions));
}
- return builder.Use(next => new WelcomePageMiddleware(next, options).Invoke);
+ var options = new WelcomePageOptions();
+ configureOptions(options);
+
+ return app.UseMiddleware(options);
}
///
/// Adds the WelcomePageMiddleware to the pipeline with the given path.
///
- ///
+ ///
///
///
- public static IApplicationBuilder UseWelcomePage(this IApplicationBuilder builder, PathString path)
+ public static IApplicationBuilder UseWelcomePage(this IApplicationBuilder app, PathString path)
{
- return UseWelcomePage(builder, new WelcomePageOptions { Path = path });
+ if (app == null)
+ {
+ throw new ArgumentNullException(nameof(app));
+ }
+
+ return app.UseWelcomePage(options => { options.Path = path; });
}
///
/// Adds the WelcomePageMiddleware to the pipeline with the given path.
///
- ///
+ ///
///
///
- public static IApplicationBuilder UseWelcomePage(this IApplicationBuilder builder, string path)
+ public static IApplicationBuilder UseWelcomePage(this IApplicationBuilder app, string path)
{
- return UseWelcomePage(builder, new WelcomePageOptions { Path = new PathString(path) });
+ if (app == null)
+ {
+ throw new ArgumentNullException(nameof(app));
+ }
+
+ return app.UseWelcomePage(options => { options.Path = new PathString(path); });
}
///
/// Adds the WelcomePageMiddleware to the pipeline.
///
- ///
+ ///
///
- public static IApplicationBuilder UseWelcomePage(this IApplicationBuilder builder)
+ public static IApplicationBuilder UseWelcomePage(this IApplicationBuilder app)
{
- return UseWelcomePage(builder, new WelcomePageOptions());
+ if (app == null)
+ {
+ throw new ArgumentNullException(nameof(app));
+ }
+
+ return app.UseWelcomePage(options => { });
}
}
}
\ No newline at end of file