/// <summary> /// Initializes a new instance of the type /// </summary> /// <param name="next">The next middleware component to execute</param> /// <param name="loggerFactory">A factory that loggers can be created from</param> /// <param name="unhandledConfiguration">Contains information about the response the handler returns</param> /// <param name="invocationCallback">A method invoked when the middleware is invoked</param> public UnhandledMiddleware(RequestDelegate next, ILoggerFactory loggerFactory, IUnhandledConfiguration unhandledConfiguration = null, InvocationCallback invocationCallback = null) { Guard.NotNull(nameof(loggerFactory), loggerFactory); _logger = loggerFactory.CreateLogger("Unhandled middleware"); using (_logger.BeginScope("Unhandled CTOR")) { if (unhandledConfiguration == null) { _contentType = UnhandledDefaults.ContentType; _content = UnhandledDefaults.Response; _responseCode = UnhandledDefaults.ResponseCode; } else { _contentType = unhandledConfiguration.ContentType ?? UnhandledDefaults.ContentType; _content = unhandledConfiguration.Response ?? UnhandledDefaults.Response; _responseCode = unhandledConfiguration.ResponseCode ?? UnhandledDefaults.ResponseCode; } _invocationCallback = invocationCallback; _logger.LogInformation("Initializing authentication middleware"); _next = next; } }
/// <summary> /// Adds unhandled request middleware to the applicaiton builder /// </summary> /// <param name="app">The application builder to add the middleware to</param> /// <param name="loggerFactory">A factory that loggers can be created from</param> /// <param name="unhandledConfiguration">Contains information about the response the handler returns</param> /// <param name="invocationCallback">A method invoked when the middleware is invoked</param> /// <returns>The original application builder for pipelining</returns> public static IApplicationBuilder UseUnhandled(this IApplicationBuilder app, ILoggerFactory loggerFactory = null, IUnhandledConfiguration unhandledConfiguration = null, InvocationCallback invocationCallback = null) { app.UseMiddleware(typeof(UnhandledMiddleware), loggerFactory, unhandledConfiguration, invocationCallback); return(app); }