Если при использовании NInject я настроил привязку для IEnumerable, это будет работать, если я напрямую запрошу IEnumerable, но не в том случае, если другой связанный объект требует IEnumerable. Это задумано?
class Program
{
static void Main(string[] args)
{
var k = new StandardKernel();
k.Bind().ToMethod(GetInts);
k.Bind().To(); // Has an IEnumerable constructor arg
var works = k.Get(); // returns the array of ints
var tst = k.Get(); // 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 Get();
}
public class Foo : IFoo
{
private int[] _vals;
public Foo(IEnumerable vals)
{
_vals = vals.ToArray();
}
public IEnumerable Get()
{
return _vals;
}
}
Подробнее здесь: https://stackoverflow.com/questions/162 ... -arg-but-n
При использовании NInject разрешение IEnumerable<T> завершается с ошибкой при внедрении аргумента ctor, но не при выполн ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение