I am using .NET 4.5, Ninject 3 with the binding by convention lib as follow:
kernel.Bind(x => x
.FromAssembliesMatching("assembly.dll")
.SelectAllClasses().InheritedFrom(typeof(ICommandHandler<>))
.BindAllInterfaces());
And this is binding properly for:
public class MyCommandHandler : ICommandHandler<MyCommand>
But doesn't bind:
public class MyGenericCommandHandler<T> : ICommandHandler<MyGenericCommand<T>>
However, the previous binding works if I add individual bindings for specific implementation of my generics class, such as:
kernel.Bind(typeof(ICommandHandler<MyGenericCommand<float>>))
.To(typeof(MyGenericCommandHandler<float>))
kernel.Bind(typeof(ICommandHandler<MyGenericCommand<int>>))
.To(typeof(MyGenericCommandHandler<int>))
But adding each individual generic type defeats the purpose of conventions and require adding binding for each possible individual type such as float, int, string, etc...
Do you know how to modify the convention or add another one (or even come with a completely different solution) to support the generic version of my command? i.e. supporting two-level generics.
TParameter
is, how you're specifying theType
you want, and it's no harm to put in more of the exception. – Ruben BartelinkICommandHandler<MyGenericCommand<float>>
coz the message says you don't ? Is it public? Is the open generic with the type necessary? Typically people have one level of open generic - theICommandHandler<>
and then have a concrete class implementing that. Unfortunately I'm more confused now but hopefully someone else can see what you're trying to do – Ruben Bartelink