Castle 3.1, FNH and RhinoServiceBus

10 views
Skip to first unread message

Matt

unread,
Oct 18, 2012, 11:18:53 AM10/18/12
to castle-pro...@googlegroups.com
Hi,

I've recently upgraded some code from an versions of the subject libraries and now I'm having problems with previously working code throwing a System.ArgumentException with a message of "An item with the same key has already been added".

I'm using a MessageModule implementation to handle sessions,  creating a session on the messagearrived event and disposing of it on MessageProcessingCompleted.  Inside my message module:
  
      [ThreadStatic]
     private static ITransaction _transaction;

       //c'tor
        public NHibernateMessageModule(ISessionFactory sessionFactory)
        {
            _sessionFactory = sessionFactory;
           
        }

        public ISession CurrentSession
        {
            get { return _session; }
        }

        //MessageArrived 
        public bool HandleBeginMessage(CurrentMessageInformation messageInfo)
        {
                 _session = _sessionFactory.OpenSession();
                 return false;
        }

       //Message Completed
        public void HandleEndMessage(CurrentMessageInformation messageInfo, Exception exception)
        {
                _session.Dispose();
               _session = null;
        }

I've removed error handling and some transaction scope code etc for clarity RhinoServiceBus injects the sessionFactory in using Castle.

The components are registered in an installer using 
       Component.For<ISessionFactory>().Instance(sessionFactory),
                Component.For<ISession>().UsingFactoryMethod((k) =>
                    {
                        NHibernateMessageModule module = (NHibernateMessageModule)k.Resolve<NHibernateMessageModule>();
                        return module.CurrentSession;
                    }).LifeStyle.Transient,

This only seems to happen when a message consumer requires another castle managed component that also requires an ISession instance.

ie.  
     //C'tor
     MyMessageConsumer(MyObject obj, ISession session)
     { 
        _obj = obj;
       _session = session;
     }

    MyObject(ISession session)
    {
        _session = session;
    }

If I take out the requirement for ISession on MyObject.  Previously to this I was using Castle 3.0, where, as I said, this all worked.  Any ideas?

Thanks in advance,

Matt
Reply all
Reply to author
Forward
0 new messages