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 k-standard-goals
#generatepages target='initialize' #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 namespace Microsoft.AspNet.Builder
{ {
/// <summary> /// <summary>
/// IApplicationBuilder extension methods for the ErrorPageMiddleware. /// <see cref="IApplicationBuilder"/> extension methods for the <see cref="DeveloperExceptionPageMiddleware"/>.
/// </summary> /// </summary>
public static class DeveloperExceptionPageExtensions public static class DeveloperExceptionPageExtensions
{ {
/// <summary> /// <summary>
/// Captures synchronous and asynchronous exceptions from the pipeline and generates HTML error responses. /// Captures synchronous and asynchronous <see cref="Exception"/> instances 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.
/// </summary> /// </summary>
/// <param name="builder"></param> /// <param name="builder">The <see cref="IApplicationBuilder"/>.</param>
/// <returns></returns> /// <returns>A reference to the <paramref name="builder"/> after the operation has completed.</returns>
public static IApplicationBuilder UseDeveloperExceptionPage(this IApplicationBuilder builder) public static IApplicationBuilder UseDeveloperExceptionPage(this IApplicationBuilder builder)
{ {
if (builder == null) if (builder == null)
@ -24,23 +23,31 @@ namespace Microsoft.AspNet.Builder
throw new ArgumentNullException(nameof(builder)); throw new ArgumentNullException(nameof(builder));
} }
return builder.UseDeveloperExceptionPage(new ErrorPageOptions()); return builder.UseDeveloperExceptionPage(options => { });
} }
/// <summary> /// <summary>
/// Captures synchronous and asynchronous exceptions from the pipeline and generates HTML error responses. /// Captures synchronous and asynchronous <see cref="Exception"/> instances 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.
/// </summary> /// </summary>
/// <param name="builder"></param> /// <param name="builder">The <see cref="IApplicationBuilder"/>.</param>
/// <param name="options"></param> /// <param name="configureOptions">A callback to configure <see cref="ErrorPageOptions"/>.</param>
/// <returns></returns> /// <returns>A reference to the <paramref name="builder"/> after the operation has completed.</returns>
public static IApplicationBuilder UseDeveloperExceptionPage(this IApplicationBuilder builder, ErrorPageOptions options) public static IApplicationBuilder UseDeveloperExceptionPage(
this IApplicationBuilder builder,
Action<ErrorPageOptions> configureOptions)
{ {
if (builder == null) if (builder == null)
{ {
throw new ArgumentNullException(nameof(builder)); throw new ArgumentNullException(nameof(builder));
} }
if (configureOptions == null)
{
throw new ArgumentNullException(nameof(configureOptions));
}
var options = new ErrorPageOptions();
configureOptions(options);
return builder.UseMiddleware<DeveloperExceptionPageMiddleware>(options); return builder.UseMiddleware<DeveloperExceptionPageMiddleware>(options);
} }
} }

View File

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

View File

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