1
美好的一天。Zenject - 安裝通用綁定
我有一個接口:
public interface IRepository<T>
{
//Stuff
}
和實施:
class Repository<T> : IRepository<T>
{
//Stuff implementation
}
現在我想在一個容器中結合在一起的這一切。
我發現Zenject是有點類似無Ninject synthax明智的,所以我嘗試了以下內容:
public class IoC : MonoInstaller
{
public override void InstallBindings()
{
Container.Bind(typeof(IPersistence<>)).To(typeof(Persistence<>));
}
}
這會拋出一個異常,當我嘗試驗證場景(編輯 - > Zenject - >驗證當前場景):
Assert hit! Invalid type given during bind command.
Expected type 'Assets.Sources.Core.Infrastructure.Repository`1[T]' to derive from
type 'IRepository`1'
所以我懷疑這只是一個不正確的方式來做通用綁定。我想知道正確的是什麼。
謝謝,現在就開始工作吧! – bashis