I\'m letting Ninject manage my ISession
and ITransaction
state in Fluent nHibnerate with the following registration method - I am wondering if it is su
I'm no expert (and have no experience with ninject), but I do agree with your 3 conclusions, and that's what I do in my projects.
Another thing I can add is that, in my opinion, transactions should be controlled EXPLICITLY and per operation, and not globally (start and beginning of request and commit at the end) like your code suggests.
This is because I believe you want to control your transaction's behaviour- commit or not (or maybe not even start, if no DB access is necessary) for every operation individually.
What I use is a management (or workflow, if you prefer) layer, which is responsible just for that. for example:
public class SomeManager : ManagersBase
{
public void DoSomething(DomainObject obj)
{
if (obj.Operation())
{
using (ITransaction tx = Session.BeginTransaction())
{
try
{
Session.Update(obj);
tx.Commit();
}
catch (MeaningfulException ex)
{
//handle
tx.Rollback();
}
}
}
}
}
hope this helps