I'm new to IoC and NHibernate, and am having a great deal of difficulty trying to get my head around best practices for dependency injection. I've spent the last couple of days looking around and reading documentation, but unfortunately the documentation I've found has been either obsolete or incomplete.
For instance, this tells me what to do, I but I have no idea how to do it. XSockets.Net - how to manage NHibernate Session Context
I have learned that, according to the official documentation, I need to use nested containers in structuremap to make sure that sessions are created and disposed appropriately for each request. Unfortunately the examples are all set within unit tests that construct their own container. I have no idea how to apply this to MVC.
If I have a repository like this
public class Repository : IRepository {
public Repository(ISession session) {
...
}
...
}
How do I make this work:
public NHibernateRegistry()
{
ISessionFactory factory = config.BuildSessionFactory();
For<IRepository>.Use<Repository>()
For<ISession>.????????
}
Or have I got it all backwards somehow?