Skip to content

Commit 42fe5cb

Browse files
committed
1. add Build SmartSqlMapper Internal Get
2. add RepositoryExtensions SessionWrap and TransactionWrap
1 parent a811bb6 commit 42fe5cb

File tree

5 files changed

+103
-4
lines changed

5 files changed

+103
-4
lines changed

src/SmartSql.DyRepository/IRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using SmartSql.Abstractions;
22
using System;
33
using System.Collections.Generic;
4+
using System.Data;
45
using System.Text;
56
using System.Threading.Tasks;
67

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using SmartSql.Abstractions;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Data;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace SmartSql.DyRepository
9+
{
10+
public static class RepositoryExtensions
11+
{
12+
public static void SessionWrap(this IRepository repository, Action handler)
13+
{
14+
repository.Session.SessionWrap(handler);
15+
}
16+
public static void SessionWrap(this IRepository repository, RequestContext context, Action handler)
17+
{
18+
repository.Session.SessionWrap(context, handler);
19+
}
20+
public static async Task SessionWrapAsync(this IRepository repository, Func<Task> handler)
21+
{
22+
await repository.Session.SessionWrapAsync(handler);
23+
}
24+
public static async Task SessionWrapAsync(this IRepository repository, RequestContext context, Func<Task> handler)
25+
{
26+
await repository.Session.SessionWrapAsync(context, handler);
27+
}
28+
public static void TransactionWrap(this IRepository repository, Action handler)
29+
{
30+
repository.Transaction.TransactionWrap(handler);
31+
}
32+
public static void TransactionWrap(this IRepository repository, IsolationLevel isolationLevel, Action handler)
33+
{
34+
repository.Transaction.TransactionWrap(isolationLevel, handler);
35+
}
36+
public static async Task TransactionWrapAsync(this IRepository repository, Func<Task> handler)
37+
{
38+
await repository.Transaction.TransactionWrapAsync(handler);
39+
}
40+
public static async Task TransactionWrapAsync(this IRepository repository, IsolationLevel isolationLevel, Func<Task> handler)
41+
{
42+
await repository.Transaction.TransactionWrapAsync(isolationLevel, handler);
43+
}
44+
}
45+
}

src/SmartSql.DyRepository/SmartSql.DyRepository.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
<Company>Ahoo Wang</Company>
77
<Title>SmartSql.DyRepository</Title>
88
<Description>SmartSql 动态代理仓储</Description>
9-
<Version>3.7.9</Version>
9+
<Version>3.7.10</Version>
1010
<PackageProjectUrl>https://github.com/Ahoo-Wang/SmartSql</PackageProjectUrl>
1111
<RepositoryUrl>https://github.com/Ahoo-Wang/SmartSql</RepositoryUrl>
1212
<PackageReleaseNotes>
13-
1. add BuildAnternalGet
13+
1. add Build SmartSqlMapper Internal Get
14+
1. add RepositoryExtensions SessionWrap and TransactionWrap
1415
</PackageReleaseNotes>
1516
<PackageIconUrl>https://raw.githubusercontent.com/Ahoo-Wang/SmartSql/master/SmartSql.png</PackageIconUrl>
1617
<Copyright>Ahoo Wang</Copyright>

src/SmartSql/SmartSql.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>netstandard2.0;net46;</TargetFrameworks>
5-
<Version>3.7.9</Version>
5+
<Version>3.7.10</Version>
66
<Authors>Ahoo Wang</Authors>
77
<Company>Ahoo Wang</Company>
88
<Copyright>Ahoo Wang</Copyright>
@@ -16,7 +16,7 @@
1616
<PackageIconUrl>https://raw.githubusercontent.com/Ahoo-Wang/SmartSql/master/SmartSql.png</PackageIconUrl>
1717
<PackageLicenseUrl>https://raw.githubusercontent.com/Ahoo-Wang/SmartSql/master/LICENSE</PackageLicenseUrl>
1818
<PackageReleaseNotes>
19-
1. fixed Dynamic child first tag is SqlText ignore prepend bug.
19+
1. add SmartSqlExtensions.SessionWrap
2020
</PackageReleaseNotes>
2121
</PropertyGroup>
2222

src/SmartSql/SmartSqlExtensions.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace SmartSql
99
{
1010
public static class SmartSqlExtensions
1111
{
12+
#region TransactionWrap
1213
public static void TransactionWrap(this ITransaction transaction, Action handler)
1314
{
1415
try
@@ -68,5 +69,56 @@ public async static Task TransactionWrapAsync(this ITransaction transaction, Iso
6869
throw ex;
6970
}
7071
}
72+
#endregion
73+
#region SessionWrap
74+
public static void SessionWrap(this ISession session, Action handler)
75+
{
76+
try
77+
{
78+
session.BeginSession();
79+
handler();
80+
}
81+
finally
82+
{
83+
session.EndSession();
84+
}
85+
}
86+
public static void SessionWrap(this ISession session, RequestContext context, Action handler)
87+
{
88+
try
89+
{
90+
session.BeginSession(context);
91+
handler();
92+
}
93+
finally
94+
{
95+
session.EndSession();
96+
}
97+
}
98+
public async static Task SessionWrapAsync(this ISession session, Func<Task> handler)
99+
{
100+
try
101+
{
102+
session.BeginSession();
103+
await handler();
104+
}
105+
finally
106+
{
107+
session.EndSession();
108+
}
109+
}
110+
public async static Task SessionWrapAsync(this ISession session, RequestContext context, Func<Task> handler)
111+
{
112+
try
113+
{
114+
session.BeginSession(context);
115+
await handler();
116+
}
117+
finally
118+
{
119+
session.EndSession();
120+
}
121+
}
122+
#endregion
71123
}
72124
}

0 commit comments

Comments
 (0)