I have the need to check if an instance of some interface has already been created by structuremap. I have tried ObjectFactory.GetInstance() but this creates a new instance of T when called and a concrete instance of T does not exist. I just want to check if an instance of T has already been created (not to create a new). I need this to force the creation of instances through a certain class).
Share
You cannot ask StructureMap if it has already created an instance of an interface.
However, it does have many lifecycle management features that allow it to control whether it creates a new instance, or returns a cached instance that it previously created.
You can tell StructureMap to make an instance HttpContextScoped, so that it returns the same instance for a given HTTP request.
It sounds like what you really want to know is how to handle NHibernate sessions in a web application with StructureMap. Try:
http://trason.net/journal/2009/10/7/bootstrapping-nhibernate-with-structuremap.html