diff --git a/事务.md b/事务.md index 7d42bc3..a80fa82 100644 --- a/事务.md +++ b/事务.md @@ -80,39 +80,7 @@ using (var uow = fsql.CreateUnitOfWork()) { } ``` -参考:在 asp.net core 中注入工作单元方法 - -```csharp -//第一步: -public class UnitOfWorkRepository : BaseRepository { - public UnitOfWorkRepository(IFreeSql fsql, IUnitOfWork uow) : base(fsql, null, null) - { - this.UnitOfWork = uow; - } -} -public class UnitOfWorkRepository : BaseRepository { - public UnitOfWorkRepository(IFreeSql fsql, IUnitOfWork uow) : base(fsql, null, null) - { - this.UnitOfWork = uow; - } -} - -//第二步: -public void ConfigureServices(IServiceCollection services) { - services.AddSingleton(fsql); - services.AddScoped(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 diff --git a/工作单元.md b/工作单元.md index 53e11c2..fb9206f 100644 --- a/工作单元.md +++ b/工作单元.md @@ -24,33 +24,7 @@ using (var uow = fsql.CreateUnitOfWork()) { } ``` -参考:在 asp.net core 中注入工作单元方法 - -```csharp -//第一步: -public class UnitOfWorkRepository : BaseRepository { - public UnitOfWorkRepository(IFreeSql fsql, IUnitOfWork uow) : base(fsql, null, null) - { - this.UnitOfWork = uow; - } -} - -//第二步: -public void ConfigureServices(IServiceCollection services) { - services.AddSingleton(fsql); - services.AddScoped(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) ## 接口定义