Pergunta

I want to be able to register an implementation by specifying a System.Type. Here's how I can do it using Castle Windsor:

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

I've tried the obvious with StructureMap:

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

Is this possible with StructureMap (2.6.4.1)?

Foi útil?

Solução

You have to call Use and For the same way - either the generic versions or the versions that take a type parameter.

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

or

IContainer container = new Container(x =>
{
    x.For<MessageQueueProcessorBase>()
     .Use<MessageQueueProcessorImpl>();
});
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top