Allow inline configure of options in UseDeveloperExceptionPage

Fixes #219
This commit is contained in:
Pranav K 2015-12-14 16:47:37 -08:00
parent 8e38584800
commit 2baf6fecf5
4 changed files with 25 additions and 16 deletions

View File

@ -8,4 +8,7 @@ use-standard-lifecycle
k-standard-goals
#generatepages target='initialize'
k command='run ../Microsoft.AspNet.Diagnostics' dnxDir='src/PageGenerator'
k command='run ../Microsoft.AspNet.Diagnostics' dnxDir='src/PageGenerator'
#xml-docs-test .clean .build-compile description='Check generated XML documentation files for errors' target='package'
k-xml-docs-test

View File

@ -7,16 +7,15 @@ using Microsoft.AspNet.Diagnostics;
namespace Microsoft.AspNet.Builder
{
/// <summary>
/// IApplicationBuilder extension methods for the ErrorPageMiddleware.
/// <see cref="IApplicationBuilder"/> extension methods for the <see cref="DeveloperExceptionPageMiddleware"/>.
/// </summary>
public static class DeveloperExceptionPageExtensions
{
/// <summary>
/// Captures synchronous and asynchronous exceptions from the pipeline and generates HTML error responses.
/// Full error details are only displayed by default if 'host.AppMode' is set to 'development' in the IApplicationBuilder.Properties.
/// Captures synchronous and asynchronous <see cref="Exception"/> instances from the pipeline and generates HTML error responses.
/// </summary>
/// <param name="builder"></param>
/// <returns></returns>
/// <param name="builder">The <see cref="IApplicationBuilder"/>.</param>
/// <returns>A reference to the <paramref name="builder"/> after the operation has completed.</returns>
public static IApplicationBuilder UseDeveloperExceptionPage(this IApplicationBuilder builder)
{
if (builder == null)
@ -24,23 +23,31 @@ namespace Microsoft.AspNet.Builder
throw new ArgumentNullException(nameof(builder));
}
return builder.UseDeveloperExceptionPage(new ErrorPageOptions());
return builder.UseDeveloperExceptionPage(options => { });
}
/// <summary>
/// Captures synchronous and asynchronous exceptions from the pipeline and generates HTML error responses.
/// Full error details are only displayed by default if 'host.AppMode' is set to 'development' in the IApplicationBuilder.Properties.
/// Captures synchronous and asynchronous <see cref="Exception"/> instances from the pipeline and generates HTML error responses.
/// </summary>
/// <param name="builder"></param>
/// <param name="options"></param>
/// <returns></returns>
public static IApplicationBuilder UseDeveloperExceptionPage(this IApplicationBuilder builder, ErrorPageOptions options)
/// <param name="builder">The <see cref="IApplicationBuilder"/>.</param>
/// <param name="configureOptions">A callback to configure <see cref="ErrorPageOptions"/>.</param>
/// <returns>A reference to the <paramref name="builder"/> after the operation has completed.</returns>
public static IApplicationBuilder UseDeveloperExceptionPage(
this IApplicationBuilder builder,
Action<ErrorPageOptions> configureOptions)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (configureOptions == null)
{
throw new ArgumentNullException(nameof(configureOptions));
}
var options = new ErrorPageOptions();
configureOptions(options);
return builder.UseMiddleware<DeveloperExceptionPageMiddleware>(options);
}
}

View File

@ -133,7 +133,7 @@ namespace Microsoft.AspNet.Diagnostics
};
var fileContent = compilationFailure
.SourceFileContent
.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
foreach (var item in compilationFailure.Messages)
{

View File

@ -5,7 +5,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Diagnostics.Views;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;
namespace Microsoft.AspNet.Diagnostics
@ -42,7 +41,7 @@ namespace Microsoft.AspNet.Diagnostics
/// <summary>
/// Process an individual request.
/// </summary>
/// <param name="context">The <see cref="Microsoft.AspNet.Http.HttpContext">.</param>
/// <param name="context">The <see cref="HttpContext"/>.</param>
/// <returns></returns>
public Task Invoke(HttpContext context)
{