首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >StructureMap:如何注册System.Type实现

StructureMap:如何注册System.Type实现
EN

Stack Overflow用户
提问于 2014-01-28 09:13:33
回答 1查看 68关注 0票数 1

我希望能够通过指定一个System.Type来注册实现。下面是我如何使用温莎城堡做这件事:

代码语言:javascript
复制
            var type = typeof(MessageQueueProcessorImpl); // configurable
            container.Register(
                Component.For<MessageQueueProcessorBase>()
                         .ImplementedBy(type)

我在StructureMap中尝试了显而易见的方法:

代码语言:javascript
复制
            var type = typeof(MessageQueueProcessorImpl); // configurable
            For<MessageQueueProcessorBase>()
                .Use(type) // <-- not accepted

这在StructureMap (2.6.4.1)中是可能的吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-28 09:52:51

您必须以同样的方式调用UseFor --无论是泛型版本还是接受类型参数的版本。

代码语言:javascript
复制
IContainer container = new Container(x =>
{
    x.For(typeof(MessageQueueProcessorBase))
     .Use(typeof(MessageQueueProcessorImpl));
});

代码语言:javascript
复制
IContainer container = new Container(x =>
{
    x.For<MessageQueueProcessorBase>()
     .Use<MessageQueueProcessorImpl>();
});
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21401298

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档