日安。
我有一个接口:
public interface IRepository<T>
{
//Stuff
}和一个实现:
class Repository<T> : IRepository<T>
{
//Stuff implementation
}现在,我想将它们绑定到一个容器中。
我发现Zenject有点类似,所以我尝试了以下方法:
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'所以我怀疑这是一种不正确的泛型绑定方式。我想知道什么才是正确的。
发布于 2017-08-31 14:30:59
这是Zenject的一个bug,现在应该已经修复了。您现在应该能够将抽象的开放泛型类型绑定到具体的开放泛型类型,如您的示例所示。
您可以尝试从github repo的主分支进行更新吗?
https://stackoverflow.com/questions/45970666
复制相似问题