1

我有很多INotificationProcessors。因为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-
4

1 回答 1

1

我会说你走对了。我在这种情况下的映射是

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

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

于 2013-06-19T04:44:39.920 回答