UnitOfWork per screen in a client app using Windsor Castle

若如初见. 提交于 2019-12-24 10:13:51

问题


I'm use to build my app using MVVM + DDD. So usually my layers relation are

View(ViewModel presenter)

ViewModel(Service service)

Service(IUnitOfWork uow, IRepository1 rep1, IRepository2 rep2)

Repository1(IUnitOfWork uow, EnitityFatory1 ef1)

Repository2(IUnitOfWork uow, EnitityFatory2 ef2)

I'm use to resolve dependency with Windsor, so all classes as per metacode above have been installed into the container usually w/ Lifestyle.Transient for all of them but UnitOfWork. In case of a web app, situation it's straight forward: I use a PerWebRequest In case of a client app, I'm use to choose Singleton, but I read some articles suggesting to create a UnitOfwork per screen/view rather than a global one to make your app more stable, specially when UoW is Nhibernate Session or MS ORM DataContext.

I'm trying to figure out how to implement UoW per screen creation policy considering of course unitofwork injected(3 times as per above metacode ) has to be always the same. If I set Lifestyle as Transient a new instance will be created per each injection... so that's not an option that fit my scenario...

How can I have an UoW instance created through the container on view/viewmodel creation, injected into any nested dependencies(as per my sample into a service and also into 2 repositories used by the service) and diposed when view/viewmodel will be disposed?

any suggestions?

来源:https://stackoverflow.com/questions/6247105/unitofwork-per-screen-in-a-client-app-using-windsor-castle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!