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
--
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/castle-project-users/-/R2qrH74mat4J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en.