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.
Video on topic: What is Castle Windsor?
Share this Post
Related posts
Where is Windsor Castle located?
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 MoreWhere is Castle Park?
Get Social With Us Connect with other fans, discuss what s happening, share your photos, and find out about events and discounts…
Read More