Home / .NET / Ninject deprecated! Long lives the new ninject service locator!

Ninject deprecated! Long lives the new ninject service locator!

We all know that people have been struggling to adapt the modularity and composition root approach Ninject and particularly the people around Ninject have been promoting over the years. After several years of stackoverflow frustration and people constantly demanding new feature for Ninject, we sat down and decided to listen carefully to the people’s needs. After endless meetings with no real agenda we finally came to the ultimate conclusion:

Ninject’s way addressing modern application composition is completely flawed. People don’t want modularity or composition roots. They always have been using Service Locator style dependency resolving and don’t want to learn new techniques. So here is the big announcement:

We will no longer support modularity and composition root; thereby completely deprecating all existing APIs and extensions for Ninject in the next major version.

The new interface we came up after a long design session will look like the following:

Ninject.Kernel.Instance.Locator.Resolve<TService>(params object[] constructorArguments);

Under the hood it will use ultra rocket science expression tree dynamic lambda compile algorithm. The algorithm is kept under copyright and will not be part of the usual Apache and MS Public licensed public code but instead be hosted on a private github repository. But what I can say here is that the output of the dynamically generated code will look like the following:

return Activator.CreateInstance(typeof(TService), constructorArguments);

We strongly advice against trying this code at home! It can lead to serious out of memory damage!

But wait there is more! We even sat down with Anders Hejlsberg and the next major C# upgrade will use Ninject under the cover. It will be possible to do DI with the new keyword. Your dreams will come true! You’ll then be able to write code like this:

new IFoo(new IBar(42));

This will then automagically (using the new compiler services) be transformed into:


Ninject.Kernel.Instance.Locator.Resolve<Foo>(Ninject.Kernel.Instance.Locator.Resolve<Bar>(42));

This feature is so powerfull that there will never again be a new Ninject release. All will be baked in the new keyword. Happy service locating!