This is my StructureMap bootstrapping:
ObjectFactory.Initialize(factory =>
{
//Business Conversation is per session
factory.ForRequestedType<IConversation>().
TheDefaultIsConcreteType<Conversation>().
CacheBy(InstanceScope.HttpSession);
//Session Factory is life time
factory.ForRequestedType<INHibernateSessionManager>().
TheDefaultIsConcreteType<NHibernateSessionManager>().
CacheBy(InstanceScope.Singleton);
});
var conversation = ObjectFactory.GetInstance<IConversation>();
When I have my Conversation set to use .CacheBy(InstanceScope.HttpSession), I get Object reference not found, however If I don't use the CacheBy it works fine. This needs to go into the session, I'm not really sure why this isn't working.
Am I doing something wrong or does this appear to be a bug in StructureMap?