문제

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)?

도움이 되었습니까?

해결책

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>();
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top