Example using Castle Windsor

What is Castle Windsor?

I've been learning a lot about Castle Windsor lately. I ran into something that surprised me yesterday. Suppose you have the following class hierarchy:

interface Service { } class ServiceA : Service { } class ServiceB : Service { }What do you think the output from this code will be?

var container = new WindsorContainer; container.Register(Component .For .ImplementedBy); container.Register(Component .For .ImplementedBy .Named("serviceb")); var service = container.Resolve; Console.WriteLine(service.GetType.Name);If you said ServiceA, then you were right! Now, what about the output from this code?

var container = new WindsorContainer; container.Register(Component .For .ImplementedBy .Named("serviceb")); container.Register(Component .For .ImplementedBy); var service = container.Resolve; Console.WriteLine(service.GetType.Name);If you said ServiceB, then maybe the title of this post gave the answer away. I expected the named service to be a special case. In other words, I thought asking for a Service implementation would always give me ServiceA, unless I specifically asked for ServiceB by name.

Source: www.mikedellanoce.com
Video on topic: What is Castle Windsor?
A day at Windsor Castle
A day at Windsor Castle
State Banquet at Windsor Castle
State Banquet at Windsor Castle
Windsor Castle
Windsor Castle

Interesting facts
Share this Post

Related posts

Where is Windsor Castle located?

Where is Windsor Castle located?

APRIL 19, 2024

The Castle is situated at the top of a steep hill. There are two stepped entrances into the Castle. There are 17 stone steps…

Read More
Where is Castle Park?

Where is Castle Park?

APRIL 19, 2024

Get Social With Us Connect with other fans, discuss what s happening, share your photos, and find out about events and discounts…

Read More