In order to make it all a bit more user-friendly, you can create extension methods on your UnitOfWork that are specific for your project (supposing that your UnitOfWork is generic and used in multiple projects) that look like this:public static class UnitOfWorkExtensions{ public static IRepositoryA GetRepositoryA( this UnitOfWork uow ) { return new RepositoryA(uow); } public static IRepositoryB GetRepositoryB( this UnitOfWork uow ) { return new RepositoryB(uow); }}然后,它使您可以执行此操作:Then, it enables you to do this:using(IUnitOfWork uow = UnitOfWork.Start()){ var repositoryA = uow.GetRepositoryA(); var repositoryB = uow.GetRepositoryB(); repositoryA.Add(insanceOfA); repositoryB.Add(instanceOfB); uow.Commit();} 这篇关于多个UnitOfWorks,ISession和存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-21 16:16