Skip to content

Commit 1319edb

Browse files
authored
Merge pull request #2232 from luoyunchong/luozq/unitofwork-manager-t
#2231 feat: 添加 DefaultRepository 和 UnitOfWorkManager 的泛型实现
2 parents ad5f445 + 04650b2 commit 1319edb

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
3+
namespace FreeSql
4+
{
5+
/// <summary>
6+
/// Default repository bound to a typed FreeSql marker.
7+
/// </summary>
8+
public class DefaultRepository<TEntity, TKey, TMark> : BaseRepository<TEntity, TKey>
9+
where TEntity : class
10+
{
11+
public DefaultRepository(IFreeSql<TMark> fsql) : base(fsql) { }
12+
public DefaultRepository(IFreeSql<TMark> fsql, UnitOfWorkManager<TMark> uowManger) : base(uowManger?.Orm ?? fsql)
13+
{
14+
uowManger?.Binding(this);
15+
}
16+
}
17+
18+
class GuidRepository<TEntity, TMark> : BaseRepository<TEntity, Guid>
19+
where TEntity : class
20+
{
21+
public GuidRepository(IFreeSql<TMark> fsql) : base(fsql) { }
22+
public GuidRepository(IFreeSql<TMark> fsql, UnitOfWorkManager<TMark> uowManger) : base(uowManger?.Orm ?? fsql)
23+
{
24+
uowManger?.Binding(this);
25+
}
26+
}
27+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace FreeSql
2+
{
3+
/// <summary>
4+
/// Typed UnitOfWork manager for multi-database scenarios.
5+
/// </summary>
6+
public class UnitOfWorkManager<TMark> : UnitOfWorkManager
7+
{
8+
public UnitOfWorkManager(IFreeSql<TMark> fsql) : base(fsql) { }
9+
}
10+
}

0 commit comments

Comments
 (0)