I finally resolved it. It appears that I was using an older version of Ninject which had an issue with the bindings of open generic types.
I was using version 3.0.1.10 and upgrading to 3.2.2.0 solved it.
Question
I am having issue with some Ninject binding code.
I am trying to bind an open generic type to a specific type based on binding name.
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
The issue I have is that each binding gets mapped twice by ninject.
I have to use named bindings because when I will need to resolve the instances, I won't know the exact type.
What is wrong with my binding ? How can I achieve what I want ?
You can post answers using C# as I am fluent in both languages.
Solution
I finally resolved it. It appears that I was using an older version of Ninject which had an issue with the bindings of open generic types.
I was using version 3.0.1.10 and upgrading to 3.2.2.0 solved it.