Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use resource filter instead of middleware
- Loading branch information
1 parent
ecb39ff
commit d98024c
Showing
4 changed files
with
79 additions
and
40 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...ional-session/aspnetcore-webapi/SqlPersistenceTS_6/WebApplication/MessageSessionFilter.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,27 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NServiceBus.TransactionalSession; | ||
|
||
public sealed class MessageSessionFilter : IAsyncResourceFilter | ||
{ | ||
public async Task OnResourceExecutionAsync(ResourceExecutingContext context, ResourceExecutionDelegate next) | ||
{ | ||
context.HttpContext.Items.Add(nameof(MessageSessionFilter), null); | ||
|
||
var session = context.HttpContext.RequestServices.GetRequiredService<ITransactionalSession>(); | ||
await session.Open(new SqlPersistenceOpenSessionOptions()); | ||
|
||
await next(); | ||
|
||
await session.Commit(); | ||
} | ||
} | ||
|
||
public sealed class RequiresTransactionalSession : ServiceFilterAttribute | ||
{ | ||
public RequiresTransactionalSession() : base(typeof(MessageSessionFilter)) | ||
{ | ||
} | ||
} |
24 changes: 0 additions & 24 deletions
24
...l-session/aspnetcore-webapi/SqlPersistenceTS_6/WebApplication/MessageSessionMiddleware.cs
This file was deleted.
Oops, something went wrong.
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