-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from marcwittke/hotfix/4.0.1
FlushFilter added again. Still necesary because of MVC design
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/environments/Backend.Fx.AspNetCore.Mvc/ErrorHandling/FlushFilter.cs
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Diagnostics; | ||
using Backend.Fx.Patterns.DependencyInjection; | ||
using Backend.Fx.Patterns.UnitOfWork; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
|
||
namespace Backend.Fx.AspNetCore.Mvc.ErrorHandling | ||
{ | ||
/// <summary> | ||
/// Enforces flushing of db changes when an action was executed, so that possible schema violation errors | ||
/// are raised before the http response starts, and our exception handling can still change the response. | ||
/// </summary> | ||
/// <remarks>This cannot be done in a middleware. MVC will start the response as soon as the controller | ||
/// action returns. The <see cref="Backend.Fx.AspNetCore.Scoping.UnitOfWorkMiddleware"/> would commit changes | ||
/// too late for the <see cref="Backend.Fx.AspNetCore.ErrorHandling.JsonErrorHandlingMiddleware"/> to | ||
/// manipulate the response status.</remarks> | ||
[DebuggerStepThrough] | ||
public class FlushFilter : IActionFilter | ||
{ | ||
private readonly IBackendFxApplication _backendFxApplication; | ||
|
||
public FlushFilter(IBackendFxApplication backendFxApplication) | ||
{ | ||
_backendFxApplication = backendFxApplication; | ||
} | ||
|
||
public void OnActionExecuting(ActionExecutingContext context) | ||
{ } | ||
|
||
public void OnActionExecuted(ActionExecutedContext context) | ||
{ | ||
// that's all: | ||
_backendFxApplication.CompositionRoot.GetInstance<ICanFlush>().Flush(); | ||
} | ||
} | ||
} |