Bekobiii
Bekobiii

Reputation: 55

Getting an IServiceProvider from Ninject

I'm currently working at a discord bot and the CommandHandler needs an IServiceProvider for the Dependency Injection but I do use Ninject does anyone know a way to retrieve a ServiceProvider from Ninject? So that my binded Modules are inside the ServiceProvider?

Couldn't figure it out myself.

I would appreciate some help :)

Upvotes: 0

Views: 558

Answers (2)

marcodt89
marcodt89

Reputation: 411

As corollary of what @Scott said, the interface IKernel extends IServiceProvider, so in your RegisterServices method, you could add a binding like this:

kernel.Bind<IServiceProvider>().ToMethod(ctx => ctx.Kernel);

Upvotes: 0

Scott Xu
Scott Xu

Reputation: 11

The StandardKernel implicitly implemented IServiceProvider interface.

Upvotes: 1

Related Questions