Getting started with Castle Windsor tutorial – Part 2


This post is, I believe, long overdue. In Part 1 of this series, I said I would demonstrate how to perform auto registration so here it is. Consider the following code

which as you can see in the registration phase is registering two different implementations “HttpFileDownloader”, “AnotherHttpFileDownloader” for the same interface “IHtmlTitleRetriever”. This is a very contrived example and there would be no reason to have two different implementations. However, it illustrates how we can perform auto-registration in cases we have several implementations of the same interface. So, here is the code:

So in effect, Castle Windsor will also automatically register “AnotherHttpFileDownloader” as long as it’s in the same assembly as “HttpFileDownloader”.

Instead of “Types”, you might be using “AllTypes” but the latter is deprecated. The version of Castle Windsor I am using is 3.2.0.

There is nothing to it really.

I will not be writing any more blog posts about the basics of Castle Windsor because it is covered sufficiently in other resources e.g. Dependency Injection in .NET.

Advertisements
Posted in .NET, Castle.Windsor, IoC

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: