1

再会。

我有一个界面:

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'

所以我怀疑这只是进行通用绑定的不正确方法。我想知道什么是正确的。

4

1 回答 1

1

这是 Zenject 的一个错误,应该从今天开始修复。您现在应该能够将抽象的开放泛型类型绑定到具体的开放泛型类型,就像在您的示例中一样。

您可以尝试从github repo的 master 分支进行更新吗?

于 2017-08-31T06:30:58.897 回答