Matt Maranda
unread,Jan 21, 2015, 4:32:04 PM1/21/15Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sharp...@googlegroups.com
Hi all,
I’ve run into a major stumbling block with a project I inherited that is using S#arp Lite. The problem seems to be that all the repositories I create have a null session. Here is an example of how I am creating the session factory, the repository, and the sample call that breaks everything.
Create Factory:
NHibernate.ISessionFactory factory = NHibernateInitializer.Initialize().BuildSessionFactory();
Because this is an ISessionFectory being created the session is null. Calling factory.OpenSession() will return a new session but does not alter the session on the factory.
Create Repository:
Repository<Person> personRepository = new Repository<Person>(factory);
I’ve included the repository at the end of this post, but it doesn’t do much of anything at this time. Most of the mapping has been handled by fluent.nhibernate and castle windsor.
Call that fails
var getAllResult = personRepository .GetAll();
What I can see by digging into S#arp Lite’s documentation on GIT is that the the Session is being set to the SessionsFactory’s current session.
SharpLite.NHibernateProvider
{
public class Repository<T> : RepositoryWithTypedId<T, int>, IRepository<T> where T : class
{
public Repository(ISessionFactory sessionFactory) : base(sessionFactory) { }
}
public class RepositoryWithTypedId<T, TId> : IRepositoryWithTypedId<T, TId> where T : class
{
public RepositoryWithTypedId(ISessionFactory sessionFactory) {
if (sessionFactory == null) throw new ArgumentNullException("sessionFactory may not be null");
_sessionFactory = sessionFactory;
}
protected virtual ISession Session {
get {
return _sessionFactory.GetCurrentSession();
}
}
Because this is an ISessionFactory without a session created at the time of initialization the session is always null. What I don’t know how to do is initialize an ISessionFactory that has an actual session at the time of initialization.
Repository
public class Repository<T> : SharpLite.NHibernateProvider.Repository<T>, IRepository<T> where T : class
{
public Repository(ISessionFactory sessionFactory) : base(sessionFactory)
{
}
}
Thank you for any help or insight you can impart