Ayende @ Rahien

Unnatural acts on source code

When IoC becomes transparent

My current project has a huge dependency on Windsor. Basically everything that goes on has to go through Windsor. This has made my life a lot simpler, but I just today noticed something interesting. Sometimes at the beginning of the application, we have defined the core services (logging, authorization authentication, etc) and then we forgot about them.

What do I mean by that?

Well, I mean that after the initial setup, we have continued to develop the application, but because of the way Windsor is structured, and because I have some defaults in the application (auto-configure controllers, for instance), it has literally been: Create new controller, expose dependencies in the constructor, move on to the real use case. Everything just falls into place without much thought, and it matches correctly.

I am very pleased with the way it turned out. :-)

Comments

Jeremy Miller
06/07/2007 11:28 PM by
Jeremy Miller

Windsor does auto-wiring out of the box right? The lack, or weakness, of that feature's always been why I've been down on Spring.Net.

Tomas Restrepo
06/07/2007 11:39 PM by
Tomas Restrepo

Do you plan on commenting on how you're setting up Windsor to get this? Sounds pretty cool...

joeyDotNet
06/08/2007 02:37 AM by
joeyDotNet

@Jeremy

Yeah, Windsor does auto-wire everything for you automatically. So Windsor (and, of course, IoC containers in general as you know) free you from having to worry about how your going to create all of your "container managed" objects and inject them in the appropriate places at the appropriate time.

A nice side effect of this, that I really like, is that your object's constructors have nothing directly relying on them, except probably your unit tests. So it's really easy to move dependencies around during refactoring and a lot of the time, you won't have to change the Windsor configuration at all.

Before I started using Windsor, I used Spring.NET for a bit. From what I remember, if you set up Spring.NET correctly, it will also auto-wire everything for you down the chain. But it's been a while since I've used it, so I'm not 100% sure.

Ayende Rahien
06/08/2007 07:54 AM by
Ayende Rahien

Yes, it auto wire by default, the main thing that made this very easy was that I have whole set of components that are automatically registered in the container (all the views and the controllers) which are where most of the stuff is happening.

Adding a service happens fairly rarely now, so it is entirely possible to simply forget about the IoC.

Ayende Rahien
06/08/2007 08:08 AM by
Ayende Rahien

except probably your unit tests.

AutoMockingContainer rocks!

joeyDotNet
06/08/2007 10:33 AM by
joeyDotNet

Oh yeah, I've been meaning to check that out. From Jacob at Eleutian right? Thanks for reminding me... :)

Matthew
06/08/2007 08:44 PM by
Matthew

How are you automatically registering the controllers?

Marcin Seredynski
06/09/2007 01:33 AM by
Marcin Seredynski

Hey Ayende! What you have just described looks like you have managed to get into programmers' heaven. I am aiming towards achieving the same goal in the future. After reading your post, I made myself a promise that I'm finally going to implement something real and use IoC there. Thanks, that was inspiring :)

Ayende Rahien
06/09/2007 03:32 AM by
Ayende Rahien

@Matthew,

Check the next post for the details

Ayende Rahien
06/09/2007 03:42 AM by
Ayende Rahien

What you have just described looks like you have managed to get into programmers' heaven.

I made sure that I now have a lot of time to debug multi threaded javascript, no really heaven in my book :-)

Jeff Brown
06/12/2007 10:23 AM by
Jeff Brown

Oh yes! This works really really well for me too.

So well that I decided to add Constructor Dependency Injection to my client-side code too! See my recent blog post...

Comments have been closed on this topic.