如何配置一个组件实例在Castle.Windsor提供多种服务? [英] How do I configure a single component instance providing multiple services in Castle.Windsor?

查看:194
本文介绍了如何配置一个组件实例在Castle.Windsor提供多种服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想配置温莎容器内,使一个单一的,单身风格的实例可以通过容器提供两个或更多的服务。

I'd like to configure the Windsor container so that a single, singleton-style instance can provide two or more services through the container.

我发现当使用在多个组件声明相同类型(基于XML的配置)将导致该类型的一个实例被创建以提供各组件的服务界面,这是不我希望的行为。

I've found that using the same type in multiple component declarations (XML-based config) will result in an instance of that type being created to provide each component's service interface, which is not the behaviour I desire.

例如:

interface IA { }
interface IB { }
class AB : IA, IB { ... }

我想AB的一个实例,以提供对IA和IB服务。

I want the one instance of AB to provide both the IA and IB services.

具体原因我想这样做,这是我的具体的DAO实现扩展多个接口。在另一面,我有一个持有不同的接口的引用几个工人组件。具体的DAO实例尊重这一点,但这些工人单独部件的构造希望自己单独的接口的实现,我渴望Castle.Windsor通过各自的服务请求,通过这些工人容器通过同一个对象实例。

The specific reason I want to do this is that my concrete DAO implementation extends multiple interfaces. On the flip side, I have several worker components which hold a reference to different interfaces. The concrete DAO instance respects this, but the constructors of these seperate worker components want the implementation of their seperate interfaces and I desire Castle.Windsor to pass the same object instance through to these worker containers via the respective service requests.

笑,我认为这是明显的泥! :P

lol, I think that was clear as mud! :P

有谁明白我的意思,和有没有人有任何想法如何,我可以通过FO组件的XML配置达致这

Does anyone understand what I mean, and has anyone got any ideas how I can acheive this through the XML configuration fo the components?

推荐答案

你检查出答案的这似乎是你在找什么这个问题(特别是论坛帖子链接)。一些例子使用的是短暂的生命周期,但我认为它会与辛格尔顿工作也。

Have you checked out the answer to this question (especially the forum post link) that appears to be what you are looking for. Some of the examples are using the Transient lifecycle but I think it will work with Singleton also.

论坛发帖是:

container.Register(Component.For<IEntityIndexController, ISnippetController>()
.ImplementedBy<SnippetController>()
.LifeStyle.Transient);



的解决方案是使用流利接口(和最近的中继版本),它是不可能配置XML我最后一次见到。然而,它可能的与设施。

祝你好运!

这篇关于如何配置一个组件实例在Castle.Windsor提供多种服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆