Fun, unique and polished Indie Games

Dependency Injection

I am currently working on Kitten Engine, a suite of tools and scripts to speed-up game development. I thought it would be great to share that with you!

Dependency Injection removes strong coupling between interface and implementation and therefore avoid spaghetti code. It allows you to create contexts. I won’t go too much into details since there are plenty of articles in the web explaining the benefit of Dependency Injection.

There are solutions that use reflections to bind the correct implementation at runtime. For now, I decided to create a simple container system. From your entry point, you create your container and the bind the implementations to the interfaces. Then, you can spread the implementation to whatever part of your code needs it.

You need to create a container to bind interface to its implementation at runtime.

KnIContainer container = new KnContainer();
container.Bind(new Implementation());

Then you can use the container to Resolve the implementation at runtime.

Interface implementation = container.Resolve();

Fun, unique and polished Indie Games

Leave a Reply