1
votes

Edit: Problem solved

This is my error message:

Message=Error activating IValueCalculator No matching bindings are available, and the type is not self-bindable. Activation path:
1) Request for IValueCalculator

Suggestions:

1) Ensure that you have defined a binding for IValueCalculator.

2) If the binding was defined in a module, ensure that the module has been loaded into the kernel.

3) Ensure you have not accidentally created more than one kernel.

4) If you are using constructor arguments, ensure that the parameter name matches the constructors parameter name.

5) If you are using automatic module loading, ensure the search path and filters are correct.

Thrown here:

IValueCalculator calc = ninjectKernel.Get<IValueCalculator>();

Here is my binding:

kernel.Bind<IValueCalculator>().To<LinqValueCalculator>();

I found this question on SO, but it did not help me(right?): Ninject WithConstructorArgument : No matching bindings are available, and the type is not self-bindable

Any idea?

2
Do the variable ninjectKernel and kernel reference the same object?Paolo Costa
well did you actually check that it's not one of the 5 suggestions? And if so, how?BatteryBackupUnit
Paolo Costa, you solved it for me. Thank youhellogoodnight

2 Answers

2
votes

I similarly facing the same issue and i found that this is because the kernel instance you passing with bind method not initialized.

I put the code please reference it.

....
var kernel = new StandardKernel();
new NinjectDI(kernel).Load();
kernel.Load(Assembly.GetExecutingAssembly());
IValueCalculator calc = ninjectKernel.Get<IValueCalculator>();
...

class NinjectDI : NinjectModule
{
    StandardKernel kernel;
    public NinjectDI(StandardKernel kernel)
    {
        this.kernel = kernel;
    }
    public override void Load()
    {
        kernel.Bind<IValueCalculator>().To<LinqValueCalculator>();
    }
}

Note: Ensure you have not accidentally created more than one kernel.

0
votes

For me it was injection dependancies that the class I was trying to bind had.

Make sure everything the class you're trying to bind requires is referenced.