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
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.
Do you plan on commenting on how you're setting up Windsor to get this? Sounds pretty cool...
@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.
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.
AutoMockingContainer _rocks_!
Oh yeah, I've been meaning to check that out. From Jacob at Eleutian right? Thanks for reminding me... :)
How are you automatically registering the controllers?
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 :)
@Matthew,
Check the next post for the details
I made sure that I now have a lot of time to debug multi threaded javascript, no really heaven in my book :-)
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...
Comment preview