再会。
我有一个界面:
public interface IRepository<T>
{
//Stuff
}
和一个实现:
class Repository<T> : IRepository<T>
{
//Stuff implementation
}
现在我想将它们全部绑定在一个容器中。
我发现 Zenject 与 Ninject 合成器有点相似,所以我尝试了以下方法:
public class IoC : MonoInstaller
{
public override void InstallBindings()
{
Container.Bind(typeof(IRepository<>)).To(typeof(Repository<>));
}
}
当我尝试验证场景时,这会引发异常(编辑 -> Zenject -> 验证当前场景):
Assert hit! Invalid type given during bind command.
Expected type 'Assets.Sources.Core.Infrastructure.Repository`1[T]' to derive from
type 'IRepository`1'
所以我怀疑这只是进行通用绑定的不正确方法。我想知道什么是正确的。