当我为IEnumerable设置绑定时使用NInject时,如果我直接请求IEnumerable,它将起作用,但如果另一个绑定对象需要IEnumerable则不行.这是设计的吗?
class Program {
static void Main(string[] args){
var k = new StandardKernel();
k.Bind<IEnumerable<int>>().ToMethod(GetInts);
k.Bind<IFoo>().To<Foo>(); //Has an IEnumberable<int> constructor arg
var works = k.Get<IEnumerable<int>>(); //returns the array of ints
var tst = k.Get<IFoo>(); //Empty integer array is passed in by ninject???
tst.Get(); //returns an empty integer array????
return;
}
public static int[] GetInts(IContext ctx){
return new int[] {1,2,3,4,5};
}
}
public interface IFoo{
IEnumerable<int> Get();
}
public class Foo : IFoo{
private int[] _vals;
public Foo(IEnumerable<int> vals){
_vals = vals.ToArray(); …Run Code Online (Sandbox Code Playgroud)