Injection dependency with Ninject for more than one web project

1
Hello, in an application I have an MVC web project and a Web API project, in the MVC project I already have the Ninject configured with the dependency injections and I would like to take advantage of it in this Web API project, I know that maybe I will have to separate it into a project for for dependency injection so I can reference it in both projects, but my question is how to do that.

Could anyone tell me?

    
asked by anonymous 03.11.2015 / 12:41

1 answer

4

You can use Mudules as explained in the documentation:

link

Basically you create a Module in a DLL, like this:

public class WarriorModule : NinjectModule
{
    public override void Load() 
    {
        Bind<IWeapon>().To<Sword>();
        Bind<Samurai>().ToSelf().InSingletonScope();
    }
}

And calls in both projects (MVC and Web Api):

 IKernel kernel = new StandardKernel(new WarriorModule());

 IDependency dependency = kernel.Get<IDependency>();
    
03.11.2015 / 13:58