7 Feb
2009

IoC libraries compared: Windsor Update

Category:UncategorizedTag: :

In case any of you read my initial post comparing various IoC libraries, I had some less than flattering words about Castle Windsor in my mass review of IoC libraries.  Naturally the Windsor crowd thought I was nuts.

So I went back and took another look at Windsor to see if I had missed something from my original assessment.  I had missed something.  Oops

Where my initial initialization looked like this:

   1: container.AddComponent("CustomerRepository",
   2:                        typeof (ICustomerRepository),
   3:                        typeof (CustomerRepository));
   4:  
   5: container.AddComponent("CustomerService",
   6:                        typeof (ICustomerService),
   7:                        typeof (CustomerService));
   8:  
   9: container.AddComponent("Form1", typeof (Form1));

And lets face it, that is some ugly code (I don’t like having to use typeof when a generic would work just as well — or even better.

If I had taken another few moments, and looked at the api through Reflector, I would have seen I could have done this:

   1: container.AddComponentWithLifestyle<ICustomerRepository, CustomerRepository>("CustomerRepository", LifestyleType.Singleton);
   2: container.AddComponentWithLifestyle<ICustomerService, CustomerService>("CustomerService",LifestyleType.Singleton);
   3: container.AddComponent<Form1>("Form1");

Much better thank you.  And this isn’t using any extra 3rd party libraries, or extra includes.  And I had completely missed those methods.

While this is good, I still have one minor grievance:  why do I have to register Form1?  Other IoC libraries do not require this.  Note, Form1 is not a dependency for any other class.  Just create it for me.   But when all is said and done, that is not bad enough grievances to not use Windsor.

Windor does have one big thing going for it after all: it does EVERYTHING you could ever want an IoC to do.  Way more than the few things I generally need from my IoC anyway.  And much if it is documented.  Although, similar to many an open source project, the documentation is slightly spotty.

My take away from all of this: double check my ReSharper intellesense options to make sure I’m seeing method variations with generics.  Below is what I was looking at.

image

See anything that indicates a method with generic parameters?  I don’t.  Why do we even have this option?

I changed one option in ReSharper:

image

And now I see this instead (which would have been much more helpful)

image

One thought on “IoC libraries compared: Windsor Update”

Comments are closed.