Hi, I have a question about how InstanceScope.Singleton works, because I am getting some unexpected results here:
I have a service that is dependent on Dao
public MetaProjectService(IMetaProjectDao metaProjectDao)
{
_metaProjectDao = metaProjectDao;
}
and I have Dao that is dependent on ISession (Nhibernate)
public MetaProjectDao(ISession nhSession)
: base(nhSession)
{}
and for structure map I have following:
ForRequestedType<IMetaProjectService>()
.TheDefaultIsConcreteType<MetaProjectService>();
//.CacheBy(InstanceScope.Singleton);
ForRequestedType<IMetaProjectDao>()
//.TheDefaultIsConcreteType<MetaProjectDao>()
//.CacheBy(InstanceScope.Singleton)
.TheDefault
.Is.ConstructedBy(() =>
{
var session = ObjectFactory
.GetNamedInstance<ISessionFactory>(
MetaProjectDao.SESSION_FACTORY_NAME)
.GetCurrentSession();
return new MetaProjectDao(session);
});
Question: If I uncomment definition for IMetaProjectService to be cached as InstanceScope.Singleton it will not work on subsequent requests as it will still hold reference to the IMetaProject instance build on the first request. There are also other dependencies that I omitted for clarity. So the question is how do I build IMetaProjectDao on each request and have this new instance be referenced by IMetaProjectService while having IMetaProjectService as singleton.