I know I can bind the following generic interface with ToFactory
method.
public interface IFoo {}
public interface IFooFactory {
TFoo Create<TFoo>() where TFoo : IFoo;
}
...
kernel.Bind<IFooFactory>().ToFactory();
This code works as expected. However, if I want to use a non-generic variant, I get a Ninject activation exception because it searches for binding of IFoo
, and so it seems that the factory extension does not recognize the Type
argument.
public interface IFooFactoryWithType {
IFoo Create(Type concreteType);
}
...
kernel.Bind<IFooFactoryWithType>().ToFactory();
Am I doing something wrong, or is it not supported this way? In my current scenario I cannot use generic version because the type is coming from a runtime parameter. I could use some reflection hack with MakeGenericMethod
and friends of course but I'd like to avoid that.