Auto Wiring for Ninject

Some of the IOC containers have so-called agreement-based automatic posting, for example, IProductRepository maps to ProductRepository without any manual posting on your part.

Is there such a thing with Ninject?

+5
source share
2 answers
// use Ninject.Extensions.Conventions for convention-based binding
kernel.Scan(scanner =>
    {
        // look for types in this assembly
        scanner.FromCallingAssembly();

        // make ISomeType bind to SomeType by default (remove the 'I'!)
        scanner.BindWith<DefaultBindingGenerator>();
    });

copied from @Pete Montgomery comment

+6
source

Ninject . . . https://github.com/ninject/ninject.extensions.conventions 3.0.0, . . , , , (, - ,....)

kernel.Bind(
    x => x.FromThisAssembly()
          .SelectAllClasses()
          .BindAllInterfaces());
+7

All Articles