Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Closed
gplwhite opened this issue Feb 7, 2018 · 1 comment
Closed

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

gplwhite opened this issue Feb 7, 2018 · 1 comment
Assignees
Milestone

Comments

@gplwhite
Copy link

gplwhite commented Feb 7, 2018

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.

@gplwhite
Copy link
Author

gplwhite commented Feb 8, 2018

I wonder if the Array/List/IEnumerable support added to KernelBase.Resolve() in #252 could have been implemented as an IBindingResolver (and maybe a custom Binding)? That would at least allow the possibility of customising or disabling this functionality rather than having it baked right into the Kernel.

@scott-xu scott-xu self-assigned this Feb 9, 2018
@scott-xu scott-xu added this to the 3.3.5 milestone Apr 12, 2022
scott-xu added a commit that referenced this issue Apr 12, 2022
glenkeane-94 pushed a commit to glenkeane-94/Nin-ject that referenced this issue Jun 17, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants