I am working on legacy code.
I have different methods of the same class that pass different arguments to the dependency constructor. I am trying to get basic use of IoC. Right now I have a StructureMap passing my arguments as follows:
var thing = ObjectFactory.GetInstance<IThingInterface>(new ExplicitArguments( new Dictionary<string, object> { { "constructorArgA", notShown }, { "constructorArgB", redacted.Property } }));
If the actual properties passed to constructorArgA and B change depending on where I am.
Instead of "constructorArgA" there is a way to configure this through the actual types, for example, you can do this when setting up an objectFactory, for example:
x.For<IHidden>().Use<RealType>() .Ctor<IConfig>().Is(new Func<IContext, IConfig>( (context) => someMethodToGetIConfig()));
If I wrote this from scratch, I would probably have structured the dependencies a little differently to avoid this, but this is not an option for me right now.
source share