views:

23

answers:

1

I have been writing a WPF DESKTOP application using NHibernate, WPF, Prism and Unity Container but have a problem in terms of Session Management in Services / Repositories and how to do it cleanly through dependency injection using Unity.

Having read Building A Desktop To Do-Application With NHibernate I now have a Session Per ViewModel / Presenter.

However, if I have several services on my viewmodel I have to pass the Session into each and every service which seems cumbersome and not quite right as I want to perform all data access through a repository.

e.g

CustomerMaintenanceViewModel
{
     service1.Session = SessionForThisPresenter;
     service2.Session = SessionForThisPresenter;
     service3.Session = SessionForThisPresenter;
     service1.GetAllSomething();
     service2.GetAllSomething();
     service3.GetAllSomething();
}

Each service is essentially a facade over a repository and I would want each repository for this presenter to be involved in the same session without explicitly setting it.

Any advice on how to handle this would be most appreciated as I am sure there is a solution quite close but I am not sure how to do it.

A: 

I suggest you look into uNhAddIns.

It has a full WPF example using MVVM.

Diego Mijelshon