mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-02-19 23:00:58 +08:00
update
34
事务.md
34
事务.md
@@ -80,39 +80,7 @@ using (var uow = fsql.CreateUnitOfWork()) {
|
||||
}
|
||||
```
|
||||
|
||||
参考:在 asp.net core 中注入工作单元方法
|
||||
|
||||
```csharp
|
||||
//第一步:
|
||||
public class UnitOfWorkRepository<TEntity, TKey> : BaseRepository<TEntity, TKey> {
|
||||
public UnitOfWorkRepository(IFreeSql fsql, IUnitOfWork uow) : base(fsql, null, null)
|
||||
{
|
||||
this.UnitOfWork = uow;
|
||||
}
|
||||
}
|
||||
public class UnitOfWorkRepository<TEntity> : BaseRepository<TEntity, int> {
|
||||
public UnitOfWorkRepository(IFreeSql fsql, IUnitOfWork uow) : base(fsql, null, null)
|
||||
{
|
||||
this.UnitOfWork = uow;
|
||||
}
|
||||
}
|
||||
|
||||
//第二步:
|
||||
public void ConfigureServices(IServiceCollection services) {
|
||||
services.AddSingleton<IFreeSql>(fsql);
|
||||
services.AddScoped<FreeSql.IUnitOfWork>(sp => fsql.CreateUnitOfWork());
|
||||
|
||||
services.AddScoped(typeof(IBaseRepository<>), typeof(UnitOfWorkRepository<>));
|
||||
services.AddScoped(typeof(BaseRepository<>), typeof(UnitOfWorkRepository<>));
|
||||
|
||||
//批量注入程序集内的所有自建仓储类,可以根据自己需要来修改
|
||||
Assembly[] assemblies = new [] { typeof(XxxRepository).Assembly };
|
||||
if (assemblies?.Any() == true)
|
||||
foreach (var asse in assemblies)
|
||||
foreach (var repo in asse.GetTypes().Where(a => a.IsAbstract == false && typeof(UnitOfWorkRepository).IsAssignableFrom(a)))
|
||||
services.AddScoped(repo);
|
||||
}
|
||||
```
|
||||
参考:参考:[在 asp.net core 中使用 UnitOfWorkManager 实现多种事务传播](https://github.com/dotnetcore/FreeSql/issues/289)
|
||||
|
||||
## 4、DbContext
|
||||
|
||||
|
||||
28
工作单元.md
28
工作单元.md
@@ -24,33 +24,7 @@ using (var uow = fsql.CreateUnitOfWork()) {
|
||||
}
|
||||
```
|
||||
|
||||
参考:在 asp.net core 中注入工作单元方法
|
||||
|
||||
```csharp
|
||||
//第一步:
|
||||
public class UnitOfWorkRepository<TEntity> : BaseRepository<TEntity, int> {
|
||||
public UnitOfWorkRepository(IFreeSql fsql, IUnitOfWork uow) : base(fsql, null, null)
|
||||
{
|
||||
this.UnitOfWork = uow;
|
||||
}
|
||||
}
|
||||
|
||||
//第二步:
|
||||
public void ConfigureServices(IServiceCollection services) {
|
||||
services.AddSingleton<IFreeSql>(fsql);
|
||||
services.AddScoped<FreeSql.IUnitOfWork>(sp => fsql.CreateUnitOfWork());
|
||||
|
||||
services.AddScoped(typeof(IBaseRepository<>), typeof(UnitOfWorkRepository<>));
|
||||
services.AddScoped(typeof(BaseRepository<>), typeof(UnitOfWorkRepository<>));
|
||||
|
||||
//批量注入程序集内的所有自建仓储类,可以根据自己需要来修改
|
||||
Assembly[] assemblies = new [] { typeof(XxxRepository).Assembly };
|
||||
if (assemblies?.Any() == true)
|
||||
foreach (var asse in assemblies)
|
||||
foreach (var repo in asse.GetTypes().Where(a => a.IsAbstract == false && typeof(UnitOfWorkRepository).IsAssignableFrom(a)))
|
||||
services.AddScoped(repo);
|
||||
}
|
||||
```
|
||||
参考:[在 asp.net core 中使用 UnitOfWorkManager 实现多种事务传播](https://github.com/dotnetcore/FreeSql/issues/289)
|
||||
|
||||
## 接口定义
|
||||
|
||||
|
||||
Reference in New Issue
Block a user