Dependency injection in Apache Ignite.NET service

Consider there is an Apache Ignite.NET cluster that provides service grid and you want to be able to execute distributed service that could access local dependency injector.

First, let’s create service itself.

As you know, Apache Ignite.NET automagically serializes services, sends them over the wire and deserializes on the node, where it will be executed. Thus, if we are using dependency injection container, Apache Ignite.NET simply does not know about it and won’t inject anything that it is not aware of. Luckily, we still can inject Apache Ignite.NET instance itself, by marking it with [InstanceResource] attribute.

Let’s introduce dependency injection container abstraction

In order to introduce Apache Ignite.NET to dependency injection container abstraction, let’s create a simple plugin.

So far, so good, we are able to wire up our DI abstraction

Finally, in application’s main method let’s complete the puzzle

That’s it, now we are ready to access our DI abstraction in Apache Ignite.NET service:

Enjoy!