문제

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"

도움이 되었습니까?

해결책

Try this:

kernel.Bind(typeof(IService<string>)).To(typeof(StringService));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top