Skip to content

Request for empty List<> returns non-empty List<> #263

@gplwhite

Description

@gplwhite

Hello,

I've run into what I consider to be a bug in v3.3.1 - specifically in the work done to resolve issue #252.

Here some code that exhibits the problem:

var kernel = new StandardKernel();

var list1 = kernel.Get<List<ChildA>>();
var child1 = kernel.Get<ChildA>();
var list2 = kernel.Get<List<ChildA>>();

List1 is returned as an empty List.
After a request for an instance of ChildA is made, subsequent requests for List return a List containing a new instance of ChildA.
As there is no explicit binding, I don't expect the second list to contain an item.

Furthermore, the particular scenario where this has manifested itself is where I use Ninject as a general object factory during JSON deserialization. The deserialization process can arbitrarily ask for items or lists of items depending on the object being deserialized. In this scenario, I never want the requested list to be populated with items - I just want an empty list of the requested type. Ideally there would be a way to opt-in (or out) of the IEnumerable<> functionality.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions