Integrating IoC Containers


“Integration” is a very overloaded term (almost as much as “implement”) and I took advantage of it in my not-so-catchy title.

I was preparing some material for some training I gave to some of my co-workers when I realized how the usage of Dependency Injection and getting comfortable with IoC containers has been assimilated into my standard way I develop enterprise software.

It has now become normal for me split service collaborators, inject them in their constructors and expect that collaborators are already there when the application is run. No hassle with configuration files, or bootstrap logic modification before it just works. And I feel weird (in a bad way) whenever I have to invoke the new() operator on a piece of code that relies to some extent on some infrastructure (configuration, database, caching, validation, etc…).

It has been a process (a long one) with some phases:

  • you have a problem handling the dependencies of your classes
  • you find out there is a manual solution for that (poor man’s DI)
  • you get overwhelmed by the amount of work
  • you find out that there is a relief for your pain
  • you get super-excited that you are using the same tool that the cool guys are using
  • you over-use it the wrong way (service location and injecting dependencies into entity classes)
  • you do not give up sobbing “it does not work, they lied to me”
  • you find out better ways of using the tools (dependency injection)
  • you learn about cool (and automated) ways to ease your pain every time you add a new class to your code and have to change the setup
  • you are too afraid of the time i would take to make it work and keep hammering your head
  • you take a leap of faith, find out it takes no time at all and curse yourself for not doing it before
  • you automate the process as much as possible and never look back
  • you take it from granted and internalize it
  • you get angry every time you do not have the infrastructure in place

As the reader can see it has been long, windy and painful but it was worth every single step. As they say in my language: “Bueno es lo que bien acaba”.

Start the process already if you feel you have to!

share class ,