I installed middleware in my main asp.net application to automatically transfer controller actions to a transaction.
public async Task Invoke(HttpContext context, MyDataContext dbContext)
{
if (context.Request.Method == "GET")
{
await _next(context);
}
else
{
using (var transaction = await dbContext.Database.BeginTransactionAsync())
{
try
{
await _next(context);
transaction.Commit();
}
catch (Exception)
{
transaction.Rollback();
throw;
}
}
}
}
However, I have one controller method (possibly more in the future) that should not be executed in a transaction. What would be the best way to make this controller action βabandonβ middleware functionality?
, [NoTransaction], . , , Invoke() , , ( , .) ?