我在 Ninject 中有以下层次结构:
public interface IReader {}
public interface IReaderAsync {}
public class Reader: IReader{}
public class ReaderAsync : IReaderAsync{}
public interface IDatabaseReader : IReader, IReaderAsync {}
public class DatabaseReader : IDatabaseReader
{
public DatabaseReader(IReader reader, IReaderAsync readerAsync){...}
}
这些类使用这些绑定在 Ninject 中按预期进行绑定、构造和加载:
Bind(typeof(IReader)).To(typeof(Reader));
Bind(typeof(IReaderAsync)).To(typeof(ReaderAsync));
Bind(typeof(IDatabaseReader)).To(typeof(DatabaseReader));
另外,我有一个单独的类,它是从一个(单独)构造的IDatabaseReader
:
public class DatabaseReader<T> : IDatabaseReader<T>
{
public DatabaseReader(IDatabaseReader databaseReader){...}
}
我使用的绑定是:
// open binding
Bind(typeof(IDatabaseReader<>)).To(typeof(DatabaseReader<>));
...
Kernel.TryGet<IDatabaseReader<TestEntry>>();
但是内核返回null ..我做错了什么?