Zenject - 安装通用绑定
Zenject - install generic binding
美好的一天。
我有一个接口:
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'
所以我怀疑这只是进行通用绑定的不正确方法。我想知道正确的是什么。
这是 Zenject 的一个错误,应该从今天开始修复。您现在应该能够将抽象的开放泛型类型绑定到具体的开放泛型类型,就像您的示例中那样。
你能尝试从 github repo 的 master 分支更新吗?
美好的一天。
我有一个接口:
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'
所以我怀疑这只是进行通用绑定的不正确方法。我想知道正确的是什么。
这是 Zenject 的一个错误,应该从今天开始修复。您现在应该能够将抽象的开放泛型类型绑定到具体的开放泛型类型,就像您的示例中那样。
你能尝试从 github repo 的 master 分支更新吗?