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!
RT @planetgeekch: #Ninject deprecated! Long lives the new ninject service locator!: http://t.co/Mh6lOX3iBl
RT @planetgeekch: #Ninject deprecated! Long lives the new ninject service locator!: http://t.co/Mh6lOX3iBl
hahahaha http://t.co/2swNJg3YrC via @danielmarbach
RT @planetgeekch: #Ninject deprecated! Long lives the new ninject service locator!: http://t.co/Mh6lOX3iBl
RT @planetgeekch: #Ninject deprecated! Long lives the new ninject service locator!: http://t.co/Mh6lOX3iBl
@tinfrey @ardalis @pluralsight @dotnetzentral be sure to also check out important news about #ninject http://t.co/5c5ArHdwXR
@planetgeekch happy April 1 to u, too 🙂
@planetgeekch #LoL
RT @planetgeekch: #Ninject deprecated! Long lives the new ninject service locator!: http://t.co/Mh6lOX3iBl
@planetgeekch @ianfdavis You guys. 🙂
RT @planetgeekch: #Ninject deprecated! Long lives the new ninject service locator!: http://t.co/Mh6lOX3iBl
RT @planetgeekch: #Ninject deprecated! Long lives the new ninject service locator!: http://t.co/Mh6lOX3iBl
RT @planetgeekch #Ninject deprecated! Long lives the new ninject service locator!: http://t.co/Xr3DFQrkn0
Haha, so the next C# version will use NInject under the hood huh? http://t.co/HAh7FwTqpG #aprilfools /cc @danielmarbach
RT @planetgeekch: #Ninject deprecated! Long lives the new ninject service locator!: http://t.co/Mh6lOX3iBl
Hehe. Nice one. RT @planetgeekch #Ninject deprecated! Long lives the new ninject service locator!: http://t.co/uGzgn1c8PT
RT @planetgeekch: #Ninject deprecated! Long lives the new ninject service locator!: http://t.co/Mh6lOX3iBl
RT @planetgeekch: #Ninject deprecated! Long lives the new ninject service locator!: http://t.co/Mh6lOX3iBl
RT @planetgeekch: #Ninject deprecated! Long lives the new ninject service locator!: http://t.co/Mh6lOX3iBl
RT @ddoomen: Haha, so the next C# version will use NInject under the hood huh? http://t.co/HAh7FwTqpG #aprilfools /cc @danielmarbach
April 1.. :p
Hi Daniel,
Is this feature implemented in c# as of today?
This was an April’s fool post