-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add UseTransactionAttribute
- Loading branch information
Showing
14 changed files
with
184 additions
and
6 deletions.
There are no files selected for viewing
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
13 changes: 13 additions & 0 deletions
13
src/SmartSql.DyRepository/Annotations/UseTransactionAttribute.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,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Text; | ||
|
||
namespace SmartSql.DyRepository.Annotations | ||
{ | ||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] | ||
public class UseTransactionAttribute : Attribute | ||
{ | ||
public IsolationLevel Level { get; set; } = IsolationLevel.Unspecified; | ||
} | ||
} |
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
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
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
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
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,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SmartSql.Middlewares | ||
{ | ||
public class TransactionMiddleware : IMiddleware | ||
{ | ||
public IMiddleware Next { get; set; } | ||
public void Invoke<TResult>(ExecutionContext executionContext) | ||
{ | ||
var isTransaction = executionContext.DbSession.Transaction != null; | ||
if (isTransaction || !executionContext.Request.Transaction.HasValue) | ||
{ | ||
Next.Invoke<TResult>(executionContext); | ||
} | ||
else | ||
{ | ||
executionContext.DbSession.TransactionWrap(executionContext.Request.Transaction.Value, | ||
() => { Next.Invoke<TResult>(executionContext); }); | ||
} | ||
} | ||
|
||
public async Task InvokeAsync<TResult>(ExecutionContext executionContext) | ||
{ | ||
var isTransaction = executionContext.DbSession.Transaction != null; | ||
if (isTransaction || !executionContext.Request.Transaction.HasValue) | ||
{ | ||
await Next.InvokeAsync<TResult>(executionContext); | ||
} | ||
else | ||
{ | ||
await executionContext.DbSession.TransactionWrapAsync(executionContext.Request.Transaction.Value, | ||
async () => { await Next.InvokeAsync<TResult>(executionContext); }); | ||
} | ||
} | ||
} | ||
} |
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
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