Class ApplicationBuilderExtensions
- Namespace
- Cuemon.Extensions.AspNetCore.Diagnostics
- Assembly
- Cuemon.Extensions.AspNetCore.dll
Extension methods for the IApplicationBuilder interface.
public static class ApplicationBuilderExtensions
- Inheritance
-
ApplicationBuilderExtensions
Examples
The following example demonstrates how to add diagnostics middleware to the ASP.NET Core pipeline using the ApplicationBuilderExtensions class.
using Cuemon.Extensions.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Builder;
namespace MyApp.Examples;
public class ApplicationBuilderExtensionsExample
{
public void Configure(IApplicationBuilder app)
{
// Add Server-Timing header middleware
app.UseServerTiming();
// Add fault descriptor exception handler (catches exceptions and returns structured error responses)
app.UseFaultDescriptorExceptionHandler();
}
}
Methods
UseFaultDescriptorExceptionHandler(IApplicationBuilder)
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 UseFaultDescriptorExceptionHandler(this IApplicationBuilder builder)
Parameters
builderIApplicationBuilderThe type that provides the mechanisms to configure an application’s request pipeline.
Returns
- IApplicationBuilder
A reference to this instance after the operation has completed.
Remarks
Extends the existing ExceptionHandlerMiddleware to include features similar to those provided by Cuemon.AspNetCore.Mvc.Filters.Diagnostics.FaultDescriptorFilter, except:
1. Unable to interact with controller applied attributes (outside scope; part of MVC context)
2. Unable to mark an exception as handled (outside scope; part of MVC context)
UseServerTiming(IApplicationBuilder)
Adds a Server-Timing HTTP header to the IApplicationBuilder request execution pipeline.
public static IApplicationBuilder UseServerTiming(this IApplicationBuilder builder)
Parameters
builderIApplicationBuilderThe type that provides the mechanisms to configure an application’s request pipeline.
Returns
- IApplicationBuilder
A reference to this instance after the operation has completed.