开发者

Share castle windsor singleton instance across multiple components

开发者 https://www.devze.com 2023-04-12 17:37 出处:网络
I want to be able to do this: <component id=\"Component1\" service=\"Foo.IFoo, Foo\" 开发者_开发问答type=\"Foo.Bar, Foo\" lifestyle=\"singleton\" />

I want to be able to do this:

<component id="Component1" service="Foo.IFoo, Foo" 开发者_开发问答type="Foo.Bar, Foo" lifestyle="singleton" />
<component id="Component2" service="Foo.IFoo, Foo" type="Foo.Bar, Foo" lifestyle="singleton" />

Such that when I do this:

IFoo foo = m_container.Resolve<IFoo>("Component1");

Or this:

IFoo foo = m_container.Resolve<IFoo>("Component2");

..I get the same singleton instance, not a seperate instance per component.

Is this possible?

Thanks.


If all you have is the interface "Name" at runtime how are you planning to call the generic Resolve<> method on the windsor container? If you truely only want one singleton instance of IFoo regardless of the comopnent "Name" then just register one as a singleton and call:

IFoo foo = m_container.Resolve<IFoo>();

If you are looking to have multiple interfaces return the same component you can look at using Forward types.

0

精彩评论

暂无评论...
验证码 换一张
取 消