1

我想通過指定System.Type來註冊實現。以下是我可以使用溫莎城堡做到這一點:StructureMap:如何註冊System.Type實現

  var type = typeof(MessageQueueProcessorImpl); // configurable 
      container.Register(
       Component.For<MessageQueueProcessorBase>() 
         .ImplementedBy(type) 

我試着StructureMap明顯:

  var type = typeof(MessageQueueProcessorImpl); // configurable 
      For<MessageQueueProcessorBase>() 
       .Use(type) // <-- not accepted 

這可能與StructureMap(2.6.4.1)?

回答

2

您必須以同樣的方式撥打UseFor - 通用版本或採用類型參數的版本。

IContainer container = new Container(x => 
{ 
    x.For(typeof(MessageQueueProcessorBase)) 
    .Use(typeof(MessageQueueProcessorImpl)); 
}); 

IContainer container = new Container(x => 
{ 
    x.For<MessageQueueProcessorBase>() 
    .Use<MessageQueueProcessorImpl>(); 
}); 
+1

這是如此明顯,當我看着它。感謝您及時的回覆! –