Skip to content

Commit

Permalink
Merge pull request #87 from marcwittke/hotfix/5.1.17
Browse files Browse the repository at this point in the history
no commit of unit of work on exception during mvc call
  • Loading branch information
marcwittke committed Nov 4, 2019
2 parents a5e4f3e + e2a1269 commit d4a91ca
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Backend.Fx.Patterns.DependencyInjection;
using Backend.Fx.Logging;
using Backend.Fx.Patterns.DependencyInjection;
using Backend.Fx.Patterns.UnitOfWork;
using Microsoft.AspNetCore.Mvc.Filters;

namespace Backend.Fx.AspNetCore.Mvc.UnitOfWork
{
public class UnitOfWorkFilter : IActionFilter
{
private static readonly ILogger Logger = LogManager.Create<UnitOfWorkFilter>();
private readonly IBackendFxApplication _application;

public UnitOfWorkFilter(IBackendFxApplication application)
Expand All @@ -29,7 +31,14 @@ public void OnActionExecuted(ActionExecutedContext context)

try
{
unitOfWork.Complete();
if (context.Exception == null)
{
unitOfWork.Complete();
}
else
{
Logger.Warn($"Preventing unit of work completion due to {context.Exception.GetType().Name}: {context.Exception.Message}");
}
}
finally
{
Expand Down

0 comments on commit d4a91ca

Please sign in to comment.