【问题标题】:Castle Windsor - One class implementing multiple interfacesCastle Windsor - 一个实现多个接口的类
【发布时间】:2009-01-12 14:46:40
【问题描述】:

我在应用程序启动时注册了我的两个接口:-

container.Register(Component.For(typeof(IEntityIndexController)).ImplementedBy(typeof(SnippetController)).LifeStyle.Transient);
container.Register(Component.For(typeof(ISnippetController)).ImplementedBy(typeof(SnippetController)).LifeStyle.Transient);

然后,当我尝试在此处使用第二个接口 (ISnippetController) 的对象上运行 IoC.Resolve 时,它​​会引发以下异常:-

无法创建组件“MyApp.Admin.Presenters.SnippetPresenter”,因为它需要满足依赖关系。 MyApp.Admin.Presenters.SnippetPresenter 正在等待以下依赖项: 服务: - 未注册的 MyApp.Admin.Controllers.ISnippetController。

如果我切换注册的顺序,它会抱怨它找不到 IEntityIndexController。因此,它似乎只获取一个类的第一个注册,然后忽略映射到同一个具体类的任何其他接口。

这里有什么我遗漏的明显东西吗? (ps 我使用 .net 3.5,windsor RC3)

【问题讨论】:

    标签: c# castle-windsor ioc-container


    【解决方案1】:

    您是否尝试过使用不同的语法进行注册 (AddComponent<>)?

    尝试更新到最新的主干版本,看看是否有帮助。对我来说似乎是一个错误。 如果没有发生,请创建一个显示错误的测试,然后提交here

    【讨论】:

      【解决方案2】:

      已更新到最新的中继 (1015) 并使用了已解决问题的转发类型。 :-)

      【讨论】:

        猜你喜欢
        • 2010-10-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-05
        相关资源
        最近更新 更多