我有以下类,用于对数据库进行特定查询并创建数据的表示模型以传回客户端浏览器。
public class SpecificFooQuery: IPresentationQuery<FooRequest, FooResult>
{
public SpecificFooQuery(ILogger logger, DbContext context)
{
this.logger = logger;
this.context = context;
}
public FooResult Get(FooRequest request)
{
return new FooResult { ... };
}
}
它实现了以下通用接口
public interface IPresentationQuery<TRequest, TResult>
where TRequest : class
where TResult : class
{
TResult Get(TRequest request);
}
但是我在编写将为我创建对象的 ninject 实例时遇到问题。这不起作用,但到目前为止我还没有真正做到这一点。
kernel.Bind<IPresentationQuery<FooResult, FooRequest>>().To<SpecificFooQuery>();
任何人都可以帮我解决这个问题,我不确定我哪里出错了,或者我需要做什么才能完成这项工作。
Error 1
The type 'SpecificFooQuery' cannot be used as type parameter
'TImplementation' in the generic type or method
'Ninject.Syntax.IBindingToSyntax<T1>.To<TImplementation>()'.
There is no implicit reference conversion from
'SpecificFooQuery' to 'IPresentationQuery<FooResult,FooRequest>'.