-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a706a8d
commit c9deee5
Showing
6 changed files
with
128 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<VersionPrefix>1.0.3</VersionPrefix> | ||
<VersionPrefix>1.0.4</VersionPrefix> | ||
<VersionSuffix></VersionSuffix> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,42 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace NetCorePal.Extensions.AspNetCore | ||
{ | ||
public static class ApplicationBuilderExtensions | ||
{ | ||
public static IApplicationBuilder UseKnownExceptionHandler(this IApplicationBuilder app, Action<KnownExceptionHandleMiddlewareOptions>? configOptions = null) | ||
public static IApplicationBuilder UseKnownExceptionHandler(this IApplicationBuilder app, | ||
Action<KnownExceptionHandleMiddlewareOptions>? configOptions = null) | ||
{ | ||
KnownExceptionHandleMiddlewareOptions options = new(); | ||
configOptions?.Invoke(options); | ||
|
||
app.UseExceptionHandler(builder => | ||
{ | ||
builder.UseMiddleware<KnownExceptionHandleMiddleware>(options, app.ApplicationServices.GetRequiredService<ILogger<KnownExceptionHandleMiddleware>>()); | ||
builder.UseMiddleware<KnownExceptionHandleMiddleware>(options, | ||
app.ApplicationServices.GetRequiredService<ILogger<KnownExceptionHandleMiddleware>>()); | ||
}); | ||
return app; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// 支持为不同的请求定义不同的配置 | ||
/// </summary> | ||
/// <param name="app"></param> | ||
/// <param name="optionFactory"></param> | ||
/// <returns></returns> | ||
public static IApplicationBuilder UseKnownExceptionHandler(this IApplicationBuilder app, | ||
Func<HttpContext, KnownExceptionHandleMiddlewareOptions> optionFactory) | ||
{ | ||
app.UseExceptionHandler(builder => | ||
{ | ||
builder.UseMiddleware<KnownExceptionHandleMiddleware>(optionFactory, | ||
app.ApplicationServices.GetRequiredService<ILogger<KnownExceptionHandleMiddleware>>()); | ||
}); | ||
return app; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters