Custom providers
Providers are specialized factory classes that Ninject uses in order to instantiate resolved types. Whenever we bind a service type to a component, we are implicitly associating that service type to a provider that can generate instances of that component. This hidden provider is a generic factory, which can create instances of every given type, and is called
StandardProvider
. Although we can often rely on StandardProvider
without having to bother about what it does behind the scenes, Ninject also allows us to create and register our custom providers just in case we need to customize the activation process as follows:
Bind<IService>().ToProvider<MyService>(); public class MyServiceProvider : Provider<MyService> { protected override ...
Get Mastering Ninject for Dependency Injection now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.