-
-
Save dcomartin/4ecb4c428c500f96c5ee1504d96cbdea 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