![](/img/trans.png)
[英]How can I Bind by convention a generic interface to a multiple generic concrete type in Ninject
[英]Ninject bind generic to concrete type
我想实现这种类型的绑定:
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>();
但这给了我一个错误,我已经看到了如何将IService <>绑定到ConcreteService <>,但是那不是我想要的。
更新将引发Ninject.ActivationException
“激活IService时出错,没有匹配的绑定可用,并且该类型不可自绑定”
尝试这个:
kernel.Bind(typeof(IService<string>)).To(typeof(StringService));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.