-
-
Save dcomartin/8207eef9eb941c118176f3988b4cf599 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public class MessageSessionFilter : IAsyncResourceFilter | |
{ | |
public async Task OnResourceExecutionAsync(ResourceExecutingContext context, ResourceExecutionDelegate next) | |
{ | |
if (context.ActionDescriptor.Parameters.Any(p => p.ParameterType == typeof(ITransactionalSession))) | |
{ | |
var session = context.HttpContext.RequestServices.GetRequiredService<ITransactionalSession>(); | |
await session.Open(new SqlPersistenceOpenSessionOptions()); | |
var result = await next(); | |
if (result.Exception is null) | |
{ | |
await session.Commit(); | |
} | |
} | |
else | |
{ | |
await next(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment