Adding back middleware initialization with options instance.

This commit is contained in:
John Luo 2015-12-23 16:04:19 -08:00
parent 20723c4067
commit 298b8baa98
7 changed files with 157 additions and 0 deletions

View File

@ -61,6 +61,34 @@ namespace Microsoft.AspNet.Builder
return app;
}
/// <summary>
/// Captures synchronous and asynchronous database related exceptions from the pipeline that may be resolved using Entity Framework
/// migrations. When these exceptions occur an HTML response with details of possible actions to resolve the issue is generated.
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/> to register the middleware with.</param>
/// <param name="options">A <see cref="DatabaseErrorPageOptions"/> that specifies options for the middleware.</param>
/// <returns>The same <see cref="IApplicationBuilder"/> instance so that multiple calls can be chained.</returns>
public static IApplicationBuilder UseDatabaseErrorPage(this IApplicationBuilder app, DatabaseErrorPageOptions options)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
app = app.UseMiddleware<DatabaseErrorPageMiddleware>(options);
if (options.EnableMigrationCommands)
{
app.UseMigrationsEndPoint(o => o.Path = options.MigrationsEndPointPath);
}
return app;
}
/// <summary>
/// Sets the options to display the maximum amount of information available.
/// </summary>

View File

@ -20,6 +20,11 @@ namespace Microsoft.AspNet.Builder
/// <returns>The same <see cref="IApplicationBuilder"/> instance so that multiple calls can be chained.</returns>
public static IApplicationBuilder UseMigrationsEndPoint(this IApplicationBuilder app)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
return app.UseMigrationsEndPoint(options => { });
}
@ -45,5 +50,25 @@ namespace Microsoft.AspNet.Builder
return app.UseMiddleware<MigrationsEndPointMiddleware>(options);
}
/// <summary>
/// Processes requests to execute migrations operations. The middleware will listen for requests to the path configured in <paramref name="options"/>.
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/> to register the middleware with.</param>
/// <param name="options">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>
public static IApplicationBuilder UseMigrationsEndPoint(this IApplicationBuilder app, MigrationsEndPointOptions options)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
return app.UseMiddleware<MigrationsEndPointMiddleware>(options);
}
}
}

View File

@ -50,5 +50,28 @@ namespace Microsoft.AspNet.Builder
configureOptions(options);
return app.UseMiddleware<DeveloperExceptionPageMiddleware>(options);
}
/// <summary>
/// Captures synchronous and asynchronous <see cref="Exception"/> instances from the pipeline and generates HTML error responses.
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/>.</param>
/// <param name="options">A <see cref="DeveloperExceptionPageOptions"/> that specifies options for the middleware.</param>
/// <returns>A reference to the <paramref name="app"/> after the operation has completed.</returns>
public static IApplicationBuilder UseDeveloperExceptionPage(
this IApplicationBuilder app,
DeveloperExceptionPageOptions options)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
return app.UseMiddleware<DeveloperExceptionPageMiddleware>(options);
}
}
}

View File

@ -74,5 +74,26 @@ namespace Microsoft.AspNet.Builder
return app.UseMiddleware<ExceptionHandlerMiddleware>(options);
}
/// <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="options"></param>
/// <returns></returns>
public static IApplicationBuilder UseExceptionHandler(this IApplicationBuilder app, ExceptionHandlerOptions options)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
return app.UseMiddleware<ExceptionHandlerMiddleware>(options);
}
}
}

View File

@ -50,5 +50,24 @@ namespace Microsoft.AspNet.Builder
return app.Use(next => new RuntimeInfoMiddleware(next, options, libraryManager, runtimeEnvironment).Invoke);
}
public static IApplicationBuilder UseRuntimeInfoPage(
this IApplicationBuilder app,
RuntimeInfoPageOptions options)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
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;
return app.Use(next => new RuntimeInfoMiddleware(next, options, libraryManager, runtimeEnvironment).Invoke);
}
}
}

View File

@ -36,6 +36,27 @@ namespace Microsoft.AspNet.Builder
return app.UseMiddleware<StatusCodePagesMiddleware>(options);
}
/// <summary>
/// Adds a StatusCodePages middleware with the given options that checks for responses with status codes
/// between 400 and 599 that do not have a body.
/// </summary>
/// <param name="app"></param>
/// <param name="options"></param>
/// <returns></returns>
public static IApplicationBuilder UseStatusCodePages(this IApplicationBuilder app, StatusCodePagesOptions options)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
return app.UseMiddleware<StatusCodePagesMiddleware>(options);
}
/// <summary>
/// Adds a StatusCodePages middleware with a default response handler that checks for responses with status codes
/// between 400 and 599 that do not have a body.

View File

@ -36,6 +36,26 @@ namespace Microsoft.AspNet.Builder
return app.UseMiddleware<WelcomePageMiddleware>(options);
}
/// <summary>
/// Adds the WelcomePageMiddleware to the pipeline with the given options.
/// </summary>
/// <param name="app"></param>
/// <param name="options"></param>
/// <returns></returns>
public static IApplicationBuilder UseWelcomePage(this IApplicationBuilder app, WelcomePageOptions options)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
return app.UseMiddleware<WelcomePageMiddleware>(options);
}
/// <summary>
/// Adds the WelcomePageMiddleware to the pipeline with the given path.
/// </summary>