I'm working with StructureMap for my IoC needs.
To make things pleasantly testable, I'm passing IContainer
instances around wherever possible, usually as constructor parameters. As a convenience, I'd like to be able to fall back to using ObjectFactory
for a parameterless constructor.
The simplest way (I thought) to do this would be to simply get the IContainer
the ObjectFactory
class wraps and pass that to the other constructor. Unfortunately, I can't find anywhere this instance is publicly exposed.
The question is:
Is there a way to get the IContainer
within ObjectFactory
so I can handle it as simply as a user-supplied instance?
Alternatively, is there a way to duplicate the configuration of the ObjectFactory
into a new Container
instance?
Example:
I would like to be able to do the following:
public class MyClass
{
public MyClass()
{
Container = ... // The ObjectFactory container instance.
}
public MyClass(IContainer container)
{
Container = container;
}
public IContainer Container { get; private set; }
}