Convention over configuration

It is not difficult to register a few service types, one by one in a small application. But what about a production application with hundreds of services which should be wired to their implementations?

Convention-based configuration allows us to bind a group of services using a convention rather than defining individual bindings for each of them. For example, you can simply ask Ninject to bind all components to their base interfaces like this:

kernel.Bind(r => r
  .FromThisAssembly()
  .SelectAllClasses()
  .BindAllInterfaces());

In order to take advantage of the Convention based configuration, we should add refererence to the Ninject's Conventions extension. We can either use NuGet to install Ninject.Extensions.Conventions ...

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.