I have been trying for three days to figure out this NHibernatefacility thing with Castle and wcf and it's really getting frustrating.
After solving a good dozen of errors, i have come to this one which seems pretty obvious but i can't solve.
This is my global.asax's Application_Start
container.AddFacility<AutoTxFacility>();
container.Register(Component.For<INHibernateInstaller>().ImplementedBy<NHibernateInstaller>());
container.AddFacility<NHibernateFacility>();
container.AddFacility<WcfFacility>();
container.Register(
Component.For<IAuthService>().ImplementedBy<AuthService>().LifestylePerWcfOperation(),
Component.For<IUserRepository>().ImplementedBy<UserRepository>().LifestylePerWcfOperation(),
Component.For<IActionWebService>().ImplementedBy<ActionWebService>().Named("ActionWebService").LifestylePerWcfOperation(),
Component.For<ISession>().LifeStyle.PerWcfOperation().UsingFactoryMethod(x => container.Resolve<ISessionManager>().OpenSession()));
This works for the first request. After that, it comes up with this error.
The factory was disposed and can no longer be used. Object name: 'this'.
the error is happening in my userrepository in this line
[Transaction]
public virtual User GetUserByCredentials(string email, string password)
{
using (var tx = session())
{
return tx.QueryOver<User>().Where(x => x.Email == email && x.Password == password).SingleOrDefault();
}
}
I am having a feeling this has to do with the LIfestyle. I have tried multiple combinations but unsuccessful. I don't know what to do at this point. I got into this Castle thing with all the facilities (that are supposed to make life easier) and it's really complicated due to the lack of documentation. I haven't been able to find a descent guide to implement all of this together, not to mention something that is not 4 years old.
Help Please!