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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With