iam using ninject.web in my aspx page in this way
my problem is with Nhibernate session management.
this is my ninject module:
public override void Load()
{
Bind<IUnitOfWork>().To<UnitOfWork>();
Bind<IAttivitaRepository>().To<AttivitaRepository>();
}
the page_load and quite every button in a single page create and dispose a unit of work at this way:
using (iuow)
{
iuow.DoSomething();
iuow.SaveAll();
}
in pageLoad works, but every other attempt in the page to use iuow with a new Using block, return that session is closed
this is my UoW impl:
public UnitOfWork()
{
_nhHelper = new SessionFactory();
InizializzaSessione();
_transaction = _session.BeginTransaction();
}
private void InizializzaSessione()
{
if (_session == null)
{
_session = _nhHelper.OpenSession();
}
Area = new AreaRepository(this._session);
Attivita = new AttivitaRepository(this._session);
Societa = new SocietaRepository(this._session);
Persona = new PersonaRepository(this._session);
}
/// <summary>
/// Salva le modifiche sulla base dati
/// </summary>
public void SaveAll()
{
if (_transaction != null)
{
_transaction.Commit();
_transaction = null;
}
}
it seems to me that iuow is resolved (whith a call to New) only at page load, so every new attempt to create Uow return last used one with session disposed.
before attimpting to use ninject what i do is simply:
using (Iuow = new UnitOfWork())
{
....
}
and all works fine
p.s.
i have to remove InRequestScope
from binding since it prevent even the page load to work