guys I need what I think is a common scenario but can't seem to make it work. I want to register all implementations so Ninject retrieves them in a constructor:
public Handler(IEnumerable<IValidation> validations)
{
// NationalIdValidation, PassportValidation, etc. are available here
}
Current registration which I didn't creates some bindings but querying validations from the codeabove retrieves no records:
Kernel.Bind(scan => scan.FromAssemblyContaining<IValidation>()
.SelectAllClasses()
.InheritedFrom<IValidation>()
.BindAllInterfaces());
Common mistakes:
1) The classes are not actually in an assembly covered by the convention
2) The classes implementing the IValidation
interface need to be public or you need to add IncludingNonPublicTypes()
to the convention:
Kernel.Bind(scan => scan.FromAssemblyContaining<IValidation>()
.SelectAllClasses()
.IncludingNonPublicTypes()
.InheritedFrom<IValidation>()
.BindAllInterfaces());
Also note that in older versions of Ninject this method was called IncludeNonePublicTypes()
(None instead of Non).
For debugging purposes, you can also implement an IBindingGenerator
and change your binding to use that. Then set a break-point inside the IBindingGenerator
to see which classes matching the conditions are actually found. If the necessary classes are found, then it can only be a problem of the Bind...
part of the implementation.