0
votes

I want to achieve this type of binding:

interface IService<T>
{
    T Get(int id);
}

class StringService : IService<string>
{
    public string Get(int id)
    {
        throw new NotImplementedException();
    }
}

kernel.Bind<IService<string>>().To<StringService>();

But it gives me an error, I've seen how to bind IService<> to ConcreteService<> already, but that's not what I want.

Update It throws Ninject.ActivationException - "Error activating IService No matching bindings are available, and the type is not self-bindable"

1
"it gives me an error". What error? Compile-time? Runtime? Exception details (message, type and stacktrace) please. - Steven
It might be that the StringService class needs to be internal or public for ninject o be able to pick up it's "default constructor" (parameterless constructor). Because the binding certailny should be correct, we are using this all the time. - BatteryBackupUnit
As the exception states, you don't have a binding for IService (you only got one for IService<string>!). So what's that IService interface? Is it actually IService<T> : IService? - BatteryBackupUnit

1 Answers

1
votes

Try this:

kernel.Bind(typeof(IService<string>)).To(typeof(StringService));