I would like to conditionally supply a constructor argument to StructureMap based on the parent type.
I am trying to achieve this with the code below.
The concrete type ProcessorSettings is a constructor argument to both TypeOne and TypeTwo.
ProcessorSettings’s constructor takes one int parameter named “frequency”.
When I try this I get a StructureMap error StructureMap Exception Code: 202
No Default Instance defined for PluginFamily . There is no more information in the error message.
x.ForConcreteType<ProcessorSettings>()
.Configure.Ctor<int>("frequency")
.Is(condition => condition.Conditional(y =>
{
y.If(t => t.ParentType == typeof(TypeOne))
.ThenIt.Is.IsThis(intVal1);
y.If(t => t.ParentType == typeof(TypeTwo))
.ThenIt.Is.IsThis(intVal2);
}));
Try using named instances instead of the conditional. If you have many variations, you can create a Convention to reduce duplication.