StructureMap:缺少请求的实例属性

时间:2013-06-13 15:38:16

标签: c# structuremap

我有很多INotificationProcessor个。对于BackorderCancelledEmailProcessor我希望它打印一些东西,而不是通过普通频道发送。所以我有一个PrintDispatcher,但它有错误,抱怨它无法解析printLocation,即使我已配置它。

相关设置:

 x.ForConcreteType<PrintDispatcher>()
   .Configure
   .Ctor<string>("printLocation")
   .Is(Settings.Default.Printer);


x.ForConcreteType<BackorderCancelledEmailProcessor>()
   .Configure
   .Ctor<INotificationDispatcher>("notificationDispatcher")
   .Is<PrintDispatcher>();

构造

BackorderCancelledEmailProcessor在构造函数中包含许多参数,其中一个是notificationDispatcher。其他所有内容都已映射(这可以不切换)。另一个的构造函数是:

public PrintDispatcher(string printLocation)

错误:

Build Error on Instance '{GUID}' (Configured Instance of BackorderCancelledEmailProcessor)
  for PluginType BackorderCancelledEmailProcessor

StructureMap.StructureMapException: StructureMap Exception Code: 205
Missing requested Instance property "printLocation" for InstanceKey "{Different GUID}"
  -Stack Trace-

1 个答案:

答案 0 :(得分:1)

我会说你是在正确的道路上。我在这个casses中的映射是

x.For<INotificationDispatcher>()
 .Use<PrintDispatcher>()
 .Ctor<string>()
    .Is(Settings.Default.Printer);
;

因此,只要需要INotificationDispatcher,就会返回已配置的PrintDispatcher