Standardize middleware to use configureOption lambda

This commit is contained in:
John Luo 2015-12-22 18:44:18 -08:00
parent 8b71e9232f
commit 9f1af65abc
9 changed files with 210 additions and 89 deletions

View File

@ -14,33 +14,33 @@ namespace Microsoft.AspNet.Builder
/// <summary> /// <summary>
/// Enables the Elm logging service, which can be accessed via the <see cref="ElmPageMiddleware"/>. /// Enables the Elm logging service, which can be accessed via the <see cref="ElmPageMiddleware"/>.
/// </summary> /// </summary>
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 // add the elm provider to the factory here so the logger can start capturing logs immediately
var factory = builder.ApplicationServices.GetRequiredService<ILoggerFactory>(); var factory = app.ApplicationServices.GetRequiredService<ILoggerFactory>();
var store = builder.ApplicationServices.GetRequiredService<ElmStore>(); var store = app.ApplicationServices.GetRequiredService<ElmStore>();
var options = builder.ApplicationServices.GetService<IOptions<ElmOptions>>(); var options = app.ApplicationServices.GetService<IOptions<ElmOptions>>();
factory.AddProvider(new ElmLoggerProvider(store, options?.Value ?? new ElmOptions())); factory.AddProvider(new ElmLoggerProvider(store, options?.Value ?? new ElmOptions()));
return builder.UseMiddleware<ElmCaptureMiddleware>(); return app.UseMiddleware<ElmCaptureMiddleware>();
} }
/// <summary> /// <summary>
/// Enables viewing logs captured by the <see cref="ElmCaptureMiddleware"/>. /// Enables viewing logs captured by the <see cref="ElmCaptureMiddleware"/>.
/// </summary> /// </summary>
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<ElmPageMiddleware>(); return app.UseMiddleware<ElmPageMiddleware>();
} }
} }
} }

View File

@ -20,9 +20,12 @@ namespace Microsoft.AspNet.Builder
/// </summary> /// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/> to register the middleware with.</param> /// <param name="app">The <see cref="IApplicationBuilder"/> to register the middleware with.</param>
/// <returns>The same <see cref="IApplicationBuilder"/> instance so that multiple calls can be chained.</returns> /// <returns>The same <see cref="IApplicationBuilder"/> instance so that multiple calls can be chained.</returns>
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()); 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. /// migrations. When these exceptions occur an HTML response with details of possible actions to resolve the issue is generated.
/// </summary> /// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/> to register the middleware with.</param> /// <param name="app">The <see cref="IApplicationBuilder"/> to register the middleware with.</param>
/// <param name="optionsAction">An action to set the options for the middleware. All options are disabled by default.</param> /// <param name="configureOptions">An action to set the options for the middleware. All options are disabled by default.</param>
/// <returns>The same <see cref="IApplicationBuilder"/> instance so that multiple calls can be chained.</returns> /// <returns>The same <see cref="IApplicationBuilder"/> instance so that multiple calls can be chained.</returns>
public static IApplicationBuilder UseDatabaseErrorPage([NotNull] this IApplicationBuilder app, [NotNull] Action<DatabaseErrorPageOptions> optionsAction) public static IApplicationBuilder UseDatabaseErrorPage(this IApplicationBuilder app, Action<DatabaseErrorPageOptions> configureOptions)
{ {
Check.NotNull(app, nameof(app)); if (app == null)
Check.NotNull(optionsAction, nameof(optionsAction)); {
throw new ArgumentNullException(nameof(app));
}
if (configureOptions == null)
{
throw new ArgumentNullException(nameof(configureOptions));
}
var options = new DatabaseErrorPageOptions(); var options = new DatabaseErrorPageOptions();
optionsAction(options); configureOptions(options);
app = app.UseMiddleware<DatabaseErrorPageMiddleware>(options); app = app.UseMiddleware<DatabaseErrorPageMiddleware>(options);
if(options.EnableMigrationCommands) if (options.EnableMigrationCommands)
{ {
app.UseMigrationsEndPoint(o => o.Path = options.MigrationsEndPointPath); 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. /// Sets the options to display the maximum amount of information available.
/// </summary> /// </summary>
/// <param name="options">The options to be configured.</param> /// <param name="options">The options to be configured.</param>
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.ShowExceptionDetails = true;
options.ListMigrations = true; options.ListMigrations = true;

View File

@ -18,26 +18,30 @@ namespace Microsoft.AspNet.Builder
/// </summary> /// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/> to register the middleware with.</param> /// <param name="app">The <see cref="IApplicationBuilder"/> to register the middleware with.</param>
/// <returns>The same <see cref="IApplicationBuilder"/> instance so that multiple calls can be chained.</returns> /// <returns>The same <see cref="IApplicationBuilder"/> instance so that multiple calls can be chained.</returns>
public static IApplicationBuilder UseMigrationsEndPoint([NotNull] this IApplicationBuilder app) public static IApplicationBuilder UseMigrationsEndPoint(this IApplicationBuilder app)
{ {
Check.NotNull(app, "builder");
return app.UseMigrationsEndPoint(options => { }); return app.UseMigrationsEndPoint(options => { });
} }
/// <summary> /// <summary>
/// Processes requests to execute migrations operations. The middleware will listen for requests to the path configured in <paramref name="optionsAction"/>. /// Processes requests to execute migrations operations. The middleware will listen for requests to the path configured in <paramref name="configureOptions"/>.
/// </summary> /// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/> to register the middleware with.</param> /// <param name="app">The <see cref="IApplicationBuilder"/> to register the middleware with.</param>
/// <param name="optionsAction">An action to set the options for the middleware.</param> /// <param name="configureOptions">An action to set the options for the middleware.</param>
/// <returns>The same <see cref="IApplicationBuilder"/> instance so that multiple calls can be chained.</returns> /// <returns>The same <see cref="IApplicationBuilder"/> instance so that multiple calls can be chained.</returns>
public static IApplicationBuilder UseMigrationsEndPoint([NotNull] this IApplicationBuilder app, [NotNull] Action<MigrationsEndPointOptions> optionsAction) public static IApplicationBuilder UseMigrationsEndPoint(this IApplicationBuilder app, Action<MigrationsEndPointOptions> configureOptions)
{ {
Check.NotNull(app, "builder"); if (app == null)
Check.NotNull(optionsAction, "optionsAction"); {
throw new ArgumentNullException(nameof(app));
}
if (configureOptions == null)
{
throw new ArgumentNullException(nameof(configureOptions));
}
var options = new MigrationsEndPointOptions(); var options = new MigrationsEndPointOptions();
optionsAction(options); configureOptions(options);
return app.UseMiddleware<MigrationsEndPointMiddleware>(options); return app.UseMiddleware<MigrationsEndPointMiddleware>(options);
} }

View File

@ -14,31 +14,31 @@ namespace Microsoft.AspNet.Builder
/// <summary> /// <summary>
/// Captures synchronous and asynchronous <see cref="Exception"/> instances from the pipeline and generates HTML error responses. /// Captures synchronous and asynchronous <see cref="Exception"/> instances from the pipeline and generates HTML error responses.
/// </summary> /// </summary>
/// <param name="builder">The <see cref="IApplicationBuilder"/>.</param> /// <param name="app">The <see cref="IApplicationBuilder"/>.</param>
/// <returns>A reference to the <paramref name="builder"/> after the operation has completed.</returns> /// <returns>A reference to the <paramref name="app"/> after the operation has completed.</returns>
public static IApplicationBuilder UseDeveloperExceptionPage(this IApplicationBuilder builder) 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 => { });
} }
/// <summary> /// <summary>
/// Captures synchronous and asynchronous <see cref="Exception"/> instances from the pipeline and generates HTML error responses. /// Captures synchronous and asynchronous <see cref="Exception"/> instances from the pipeline and generates HTML error responses.
/// </summary> /// </summary>
/// <param name="builder">The <see cref="IApplicationBuilder"/>.</param> /// <param name="app">The <see cref="IApplicationBuilder"/>.</param>
/// <param name="configureOptions">A callback to configure <see cref="DeveloperExceptionPageOptions"/>.</param> /// <param name="configureOptions">A callback to configure <see cref="DeveloperExceptionPageOptions"/>.</param>
/// <returns>A reference to the <paramref name="builder"/> after the operation has completed.</returns> /// <returns>A reference to the <paramref name="app"/> after the operation has completed.</returns>
public static IApplicationBuilder UseDeveloperExceptionPage( public static IApplicationBuilder UseDeveloperExceptionPage(
this IApplicationBuilder builder, this IApplicationBuilder app,
Action<DeveloperExceptionPageOptions> configureOptions) Action<DeveloperExceptionPageOptions> configureOptions)
{ {
if (builder == null) if (app == null)
{ {
throw new ArgumentNullException(nameof(builder)); throw new ArgumentNullException(nameof(app));
} }
if (configureOptions == null) if (configureOptions == null)
@ -48,7 +48,7 @@ namespace Microsoft.AspNet.Builder
var options = new DeveloperExceptionPageOptions(); var options = new DeveloperExceptionPageOptions();
configureOptions(options); configureOptions(options);
return builder.UseMiddleware<DeveloperExceptionPageMiddleware>(options); return app.UseMiddleware<DeveloperExceptionPageMiddleware>(options);
} }
} }
} }

View File

@ -18,11 +18,12 @@ namespace Microsoft.AspNet.Builder
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseExceptionHandler(this IApplicationBuilder app, string errorHandlingPath) public static IApplicationBuilder UseExceptionHandler(this IApplicationBuilder app, string errorHandlingPath)
{ {
var options = new ExceptionHandlerOptions() if (app == null)
{ {
ExceptionHandlingPath = new PathString(errorHandlingPath) throw new ArgumentNullException(nameof(app));
}; }
return app.UseMiddleware<ExceptionHandlerMiddleware>(options);
return app.UseExceptionHandler(options => { options.ExceptionHandlingPath = new PathString(errorHandlingPath); });
} }
/// <summary> /// <summary>
@ -34,13 +35,43 @@ namespace Microsoft.AspNet.Builder
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseExceptionHandler(this IApplicationBuilder app, Action<IApplicationBuilder> configure) public static IApplicationBuilder UseExceptionHandler(this IApplicationBuilder app, Action<IApplicationBuilder> configure)
{ {
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
if (configure == null)
{
throw new ArgumentNullException(nameof(configure));
}
var subAppBuilder = app.New(); var subAppBuilder = app.New();
configure(subAppBuilder); configure(subAppBuilder);
var exceptionHandlerPipeline = subAppBuilder.Build(); var exceptionHandlerPipeline = subAppBuilder.Build();
var options = new ExceptionHandlerOptions()
return app.UseExceptionHandler(options => { options.ExceptionHandler = exceptionHandlerPipeline; });
}
/// <summary>
/// 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.
/// </summary>
/// <param name="app"></param>
/// <param name="configureOptions"></param>
/// <returns></returns>
public static IApplicationBuilder UseExceptionHandler(this IApplicationBuilder app, Action<ExceptionHandlerOptions> 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<ExceptionHandlerMiddleware>(options); return app.UseMiddleware<ExceptionHandlerMiddleware>(options);
} }
} }

View File

@ -1,7 +1,6 @@
// 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. // 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; using Microsoft.AspNet.Http;
namespace Microsoft.AspNet.Diagnostics namespace Microsoft.AspNet.Diagnostics

View File

@ -10,33 +10,45 @@ namespace Microsoft.AspNet.Builder
{ {
public static class RuntimeInfoExtensions 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( public static IApplicationBuilder UseRuntimeInfoPage(
this IApplicationBuilder builder, this IApplicationBuilder app,
RuntimeInfoPageOptions options) Action<RuntimeInfoPageOptions> 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) var libraryManager = app.ApplicationServices.GetService(typeof(ILibraryManager)) as ILibraryManager;
{ var runtimeEnvironment = app.ApplicationServices.GetService(typeof(IRuntimeEnvironment)) as IRuntimeEnvironment;
throw new ArgumentNullException(nameof(options)); var options = new RuntimeInfoPageOptions();
} configureOptions(options);
var libraryManager = builder.ApplicationServices.GetService(typeof(ILibraryManager)) as ILibraryManager; return app.Use(next => new RuntimeInfoMiddleware(next, options, libraryManager, runtimeEnvironment).Invoke);
var runtimeEnvironment = builder.ApplicationServices.GetService(typeof(IRuntimeEnvironment)) as IRuntimeEnvironment;
return builder.Use(next => new RuntimeInfoMiddleware(next, options, libraryManager, runtimeEnvironment).Invoke);
} }
} }
} }

View File

@ -17,14 +17,21 @@ namespace Microsoft.AspNet.Builder
/// between 400 and 599 that do not have a body. /// between 400 and 599 that do not have a body.
/// </summary> /// </summary>
/// <param name="app"></param> /// <param name="app"></param>
/// <param name="options"></param> /// <param name="configureOptions"></param>
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseStatusCodePages(this IApplicationBuilder app, StatusCodePagesOptions options) public static IApplicationBuilder UseStatusCodePages(this IApplicationBuilder app, Action<StatusCodePagesOptions> configureOptions)
{ {
if (app == null) if (app == null)
{ {
throw new ArgumentNullException(nameof(app)); throw new ArgumentNullException(nameof(app));
} }
if (configureOptions == null)
{
throw new ArgumentNullException(nameof(configureOptions));
}
var options = new StatusCodePagesOptions();
configureOptions(options);
return app.UseMiddleware<StatusCodePagesMiddleware>(options); return app.UseMiddleware<StatusCodePagesMiddleware>(options);
} }
@ -37,7 +44,12 @@ namespace Microsoft.AspNet.Builder
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseStatusCodePages(this IApplicationBuilder app) 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 => { });
} }
/// <summary> /// <summary>
@ -49,7 +61,16 @@ namespace Microsoft.AspNet.Builder
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseStatusCodePages(this IApplicationBuilder app, Func<StatusCodeContext, Task> handler) public static IApplicationBuilder UseStatusCodePages(this IApplicationBuilder app, Func<StatusCodeContext, Task> 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; });
} }
/// <summary> /// <summary>
@ -62,7 +83,12 @@ namespace Microsoft.AspNet.Builder
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseStatusCodePages(this IApplicationBuilder app, string contentType, string bodyFormat) 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); var body = string.Format(CultureInfo.InvariantCulture, bodyFormat, context.HttpContext.Response.StatusCode);
context.HttpContext.Response.ContentType = contentType; context.HttpContext.Response.ContentType = contentType;
@ -80,10 +106,15 @@ namespace Microsoft.AspNet.Builder
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseStatusCodePagesWithRedirects(this IApplicationBuilder app, string locationFormat) public static IApplicationBuilder UseStatusCodePagesWithRedirects(this IApplicationBuilder app, string locationFormat)
{ {
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
if (locationFormat.StartsWith("~")) if (locationFormat.StartsWith("~"))
{ {
locationFormat = locationFormat.Substring(1); locationFormat = locationFormat.Substring(1);
return UseStatusCodePages(app, context => return app.UseStatusCodePages(context =>
{ {
var location = string.Format(CultureInfo.InvariantCulture, locationFormat, context.HttpContext.Response.StatusCode); var location = string.Format(CultureInfo.InvariantCulture, locationFormat, context.HttpContext.Response.StatusCode);
context.HttpContext.Response.Redirect(context.HttpContext.Request.PathBase + location); context.HttpContext.Response.Redirect(context.HttpContext.Request.PathBase + location);
@ -92,7 +123,7 @@ namespace Microsoft.AspNet.Builder
} }
else else
{ {
return UseStatusCodePages(app, context => return app.UseStatusCodePages(context =>
{ {
var location = string.Format(CultureInfo.InvariantCulture, locationFormat, context.HttpContext.Response.StatusCode); var location = string.Format(CultureInfo.InvariantCulture, locationFormat, context.HttpContext.Response.StatusCode);
context.HttpContext.Response.Redirect(location); context.HttpContext.Response.Redirect(location);
@ -110,10 +141,15 @@ namespace Microsoft.AspNet.Builder
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseStatusCodePages(this IApplicationBuilder app, Action<IApplicationBuilder> configuration) public static IApplicationBuilder UseStatusCodePages(this IApplicationBuilder app, Action<IApplicationBuilder> configuration)
{ {
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
var builder = app.New(); var builder = app.New();
configuration(builder); configuration(builder);
var tangent = builder.Build(); var tangent = builder.Build();
return UseStatusCodePages(app, context => tangent(context.HttpContext)); return app.UseStatusCodePages(context => tangent(context.HttpContext));
} }
/// <summary> /// <summary>
@ -125,7 +161,12 @@ namespace Microsoft.AspNet.Builder
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseStatusCodePagesWithReExecute(this IApplicationBuilder app, string pathFormat) 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)); var newPath = new PathString(string.Format(CultureInfo.InvariantCulture, pathFormat, context.HttpContext.Response.StatusCode));

View File

@ -16,49 +16,71 @@ namespace Microsoft.AspNet.Builder
/// <summary> /// <summary>
/// Adds the WelcomePageMiddleware to the pipeline with the given options. /// Adds the WelcomePageMiddleware to the pipeline with the given options.
/// </summary> /// </summary>
/// <param name="builder"></param> /// <param name="app"></param>
/// <param name="options"></param> /// <param name="configureOptions"></param>
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseWelcomePage(this IApplicationBuilder builder, WelcomePageOptions options) public static IApplicationBuilder UseWelcomePage(this IApplicationBuilder app, Action<WelcomePageOptions> 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<WelcomePageMiddleware>(options);
} }
/// <summary> /// <summary>
/// Adds the WelcomePageMiddleware to the pipeline with the given path. /// Adds the WelcomePageMiddleware to the pipeline with the given path.
/// </summary> /// </summary>
/// <param name="builder"></param> /// <param name="app"></param>
/// <param name="path"></param> /// <param name="path"></param>
/// <returns></returns> /// <returns></returns>
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; });
} }
/// <summary> /// <summary>
/// Adds the WelcomePageMiddleware to the pipeline with the given path. /// Adds the WelcomePageMiddleware to the pipeline with the given path.
/// </summary> /// </summary>
/// <param name="builder"></param> /// <param name="app"></param>
/// <param name="path"></param> /// <param name="path"></param>
/// <returns></returns> /// <returns></returns>
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); });
} }
/// <summary> /// <summary>
/// Adds the WelcomePageMiddleware to the pipeline. /// Adds the WelcomePageMiddleware to the pipeline.
/// </summary> /// </summary>
/// <param name="builder"></param> /// <param name="app"></param>
/// <returns></returns> /// <returns></returns>
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 => { });
} }
} }
} }