osharp3使用经验:整合DbContextScope 文章 1

osharp3的事务处理是跳过savechangeing方法来控制的,没有DbContextScope专业

DbContextScope管理dbcontext的优劣本文不讨论

整合过程:

1、在.Data.Entity/Extensions/ServiceCollectionExtensions.cs

注入1DbContextScopeFactory 与 IAmbientDbContextLocator,

并且去掉却来的IUnitOfWork注入,

就是把dbContext完全交DbContextScope管理

如图

osharp3使用经验:整合DbContextScope 文章 1_第1张图片

二、改造Repository<TEntity, TKey>

osharp3使用经验:整合DbContextScope 文章 1_第2张图片

三、应用服务层注入 public IDbContextScopeFactory _dbContextScopeFactory { get; set; }

osharp3使用经验:整合DbContextScope 文章 1_第3张图片

四、使用方法

五:改造DbContextScope,加方法 Add DbContext Get(Type _DbContextType);

改动如下

osharp3使用经验:整合DbContextScope 文章 1_第4张图片

相关链接:

https://github.com/shiningrise/DbContextScope/commit/8d48f584d0c1a159e2688f2dda5135356137d4b0

https://github.com/i66soft/osharp

https://github.com/mehdime/DbContextScope

你可能感兴趣的:(osharp3使用经验:整合DbContextScope 文章 1)