错误CS0311类型'ClassLibrary1.Concrete.EFGameRepository'不能 在泛型类型中用作类型参数'TImplementation' 方法'IBindingToSyntax.To()'。 没有隐式引用转换 'ClassLibrary1.Concrete.EFGameRepository'来 'ClassLibrary1.Abstract.IGameRepository'。
以下是代码:
namespace GameStore.WebUI.Infrastructure
{
public class NinjectDependencyResolver : IDependencyResolver
{
private IKernel kernel;
public NinjectDependencyResolver(IKernel kernelParam)
{
kernel = kernelParam;
AddBindings();
}
public object GetService(Type serviceType)
{
return kernel.TryGet(serviceType);
}
public IEnumerable<object> GetServices(Type serviceType)
{
return kernel.GetAll(serviceType);
}
private void AddBindings()
{
kernel.Bind<IGameRepository>().To<EFGameRepository>();
}
}
}
EFGameRepository
public class EFGameRepository
{
EFDbContext context = new EFDbContext();
public IEnumerable<Game> Games { get { return context.Games; } }
}
答案 0 :(得分:0)
要解决此问题,EFGameRepository
必须实施IGameRepository
public class EFGameRepository : IGameRepository
{
// implement IGameRepository members implicit or explicit
}