Wednesday, October 1, 2008

Dependency Injection in XNA

The benefits of using Dependency Injection/IoC are more or less obvious, for an "academic" argument search the internets. Anyway, I started coding using the "Manager classes with static methods" style seen in most of the XNA tutorials and pretty soon my code became "spaghetized" and I realized that I really missed having an IoC container. After a few searches it appeared that I would have to make one - I would have used or Castle or Unity or whatever but all of them seem to be using Reflection.Emit which is not available on the Xbox360. Plus they just do way to much for what a game needs.

Code is not ready for public consumption just yet, but I'll clean it up and publish as soon as I can.

Anyway, it's called Radiality and it has all the features you would expect from an IoC container, life cycle management, singletons, prototypes, auto-wiring, late injection, look up by interface or name and a few more thing I forgot about.

Here is what it looks like in action.