My repositories all take ISession in the constructor:
protected Repository(ISession session)
{
this.session = session;
}
private readonly ISession session;
In an Asp.Net MVC application, using StructureMap, how would I go about setting up ISession in my the StructureMap Registry? Would I need to to add SessionFactory to the container also? Does FluentNHibernate change things?
You should register ISession using a factory method.
Another options (not always the best, but easy to use) is to:
Implement ISession and ISessionFactory interfaces (SessionProxy and SessionFactoryProxy).
This way you can just register ISession (implemented by SessionAggregator) and ISessionFactory (SessionFactoryAggreagator) and any DI framework will resolve ISession easily.
This is good if your DI does not support factory method (I don't know if Structure Map does).
I have added these implementation to my Commons assembly so I should not reimplement it every time.
EDIT: Now, to make use of ISession in web application:
The code can look like:
This question & answers might help you.
One way to go - steal nhibernate session management from "S#arp Architecture". Works great.