Skip to content

shawndube/Ninject.Extensions.Conventions

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Convention based binding for Ninject

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 77.5%
  • Smalltalk 21.5%
  • Shell 1.0%