Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windsor register singleton component for multiple interfaces

Tags:

I want to register one class with 2 interfaces in Castle.Windsor.

does this code work... Will I have only one instance for both interfaces...

Component.For<IEnvironment>().ImplementedBy<OutlookEnvironment>().LifestyleSingleton() Component.For<IOutlookEnvironment>().ImplementedBy<OutlookEnvironment>().LifestyleSingleton() 

I need to double check this because my environment should always be the same instance...

So when I resolve using the IEnvironment interface I should get the same instance as when using IOutlookEnvironment to resolve the component

like image 249
Marco Avatar asked Feb 07 '13 17:02

Marco


1 Answers

You need to use the use multi-generic-parameter overload of the Component.For method

Component.For<IEnvironment, IOutlookEnvironment>()          .ImplementedBy<OutlookEnvironment>()          .LifestyleSingleton() 

See also in the documentation: Registering component with multiple services section.

like image 141
nemesv Avatar answered Nov 02 '22 10:11

nemesv