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

这是如此明显,当我看着它。感谢您及时的回复! –