Skip to content

Latest commit

 

History

History
37 lines (28 loc) · 1.78 KB

README.md

File metadata and controls

37 lines (28 loc) · 1.78 KB

Ninject.Extensions.Conventions NuGet Version NuGet Downloads

Provides a configuration by convention extension for Ninject.

Sample uses

Binding default single interface

IKernel kernel = new StandardKernel();

kernel.Bind(x =>
    {
        x.FromThisAssembly() // Scans currently assembly
         .SelectAllClasses() // Retrieve all non-abstract classes
         .BindDefaultInterface() // Binds the default interface to them;
    });

Default interface in this scenario means that if your interface is named IService, then the class named Service will be binded to it. However, the class SqlBasedService will not be binded and will fail to retrieve the implementation.

Binding single interface

IKernel kernel = new StandardKernel();

kernel.Bind(x =>
    {
        x.FromThisAssembly() // Scans currently assembly
         .SelectAllClasses() // Retrieve all non-abstract classes
         .BindSingleInterface() // Binds the default interface to them;
    });

Binding single interface means that you are expecting to have one implementation per classes found. This would bind SqlBasedService to IService as well as Service to IService but would not bind SqlBasedService and Service to an IService.

You can find more details in wiki page.

CI build status

Build Status