问题
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