ninject / Ninject

the ninja of .net dependency injectors
http://ninject.org/
Other
2.68k stars 528 forks source link

How to use ninject in a .netcore 2.1 API project #278

Open LFrancisMMU opened 5 years ago

LFrancisMMU commented 5 years ago

Hi, I have a .netcore 2.1 API which uses the inbuild .netcore DI. I would like to use Ninject instead due to its autowiring property. I could not find any exampleas as to how to do it. Could anyone please direct me in correct path or any documentations regarding this. Thanks in advance.

msnelling commented 5 years ago

I would also like this. From what I can see, Ninject is missing implementations of the Microsoft.Extensions.DependencyInjection.Abstractions interfaces.

This is how Autofac does it... https://github.com/autofac/Autofac.Extensions.DependencyInjection/tree/develop/src/Autofac.Extensions.DependencyInjection

polterguy commented 5 years ago

Here's my own code that does this. It's based upon collections of snippets from StackOverflow and blogs. If you start looking at the "Startup.cs", and pays particularly close attention to the class(es) inside the "/init/" folder, most of which are related to wiring up Ninject, you could probably figure it out after a couple of hours ...

As of today, most classes except FileUploadOperation, Configurator and InitializeDatabase in the "init" folder are somehow related to wiring up Ninject. This works perfectly with ASP.NET Core 2.2, and probably all other versions of ASP.NET Core.

I am using it myself to consume Ninject in all of my web APIs.

PS! I'd enjoy getting feedback on whether or not this code is doing things correctly or not, if there are some Black Belt Ninject gurus out there reading this ...

lord-executor commented 3 years ago

Probably a bit late, but for future reference: https://github.com/lord-executor/Ninject.Web.AspNetCore happens to be a fully functional Ninject integration for ASP.NET Core (2.2+ and .NET 5).

Although it was built explicitly for ASP.NET Core integration, the implementation contains all that is needed to replace Microsoft.Extensions.DependencyInjection(.Abstractions) in any other use case as well.