Summary

We studied the most common DI patterns and antipatterns related to Ninject. Multibinding means binding a single service type to multiple concrete types and has two scenarios of the Plugin model and contextual binding. Providers are a kind of factories that are specialized for Ninject to be used for creating new instances of resolved types. We can create our own providers by deriving from the Provider<T> class. A Factory method is a substitute for Provider, where the activation logic is short and simple and instantiation of the service type is not as simple as calling the constructor of the implementation. Introducing a dependency as Lazy<dependency> informs Ninject to defer instantiation of that dependency whenever that dependency is requested. ...

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.