1
일부 Ninject 바인딩 코드에 문제가 있습니다.Ninject 명명 된 열기 일반 유형 바인딩은 단일 바인드 호출에 대해 두 번 바인드합니다.
오픈 제네릭 형식을 바인딩 이름을 기반으로 특정 형식에 바인딩하려고합니다.
Sub Main
dim k as new StandardKernel()
k.Bind(GetType(SomeService(of))).To(gettype(SomeService(of A))).Named("A")
k.Bind(GetType(SomeService(of))).To(gettype(SomeService(of B))).Named("B")
k.Bind(GetType(SomeService(of))).To(gettype(SomeService(of C))).Named("C")
k.Get(GetType(SomeService(of)), "B") ' Fails because the binding is defined more than once
k.GetAll(GetType(SomeService(of)), "B") ' Returns two instances of SomeService(of B)
end sub
public class SomeService(of T)
end class
public class A
end class
public class B
end class
public class C
end class
문제는 각 바인딩이 ninject에 의해 두 번 매핑된다는 것입니다.
인스턴스를 해결해야 할 때 정확한 유형을 알 수 없으므로 명명 된 바인딩을 사용해야합니다.
제 바인딩에 어떤 문제가 있습니까? 내가 원하는 것을 어떻게 얻을 수 있습니까?
두 언어 모두 유창하므로 C#을 사용하여 답변을 게시 할 수 있습니다.
그것은'SomeService'가 instanciatable 유형 인으로 할 필요가 있습니다. 대신'ISomeService'를'SomeService'에 바인딩 해 보았습니까? 나는 문제를 제기 할 것이다. @ ninject github. 이것은 확실히 흥미로운 행동입니다. – BatteryBackupUnit