我想根据父类型有条件地为 StructureMap 提供构造函数参数。我正在尝试使用下面的代码来实现这一点。
具体类型 ProcessorSettings 是 TypeOne 和 TypeTwo 的构造函数参数。ProcessorSettings 的构造函数采用一个名为“频率”的 int 参数。
当我尝试这个时,我得到一个 StructureMap 错误StructureMap Exception Code: 202 No Default Instance defined for PluginFamily。错误消息中没有更多信息。
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);
}));