Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Bind/Rebind to a constant generic List always returns an empty list #333

Closed
pcroc opened this issue Jan 28, 2019 · 4 comments · Fixed by #345
Closed

Bind/Rebind to a constant generic List always returns an empty list #333

pcroc opened this issue Jan 28, 2019 · 4 comments · Fixed by #345

Comments

@pcroc
Copy link

pcroc commented Jan 28, 2019

StandardKernel kernel = new StandardKernel();

List<int> list = new List<int> { 1, 2, 3, 4, 5 };
kernel.Bind<List<int>>().ToConstant(list).InSingletonScope();

var result = kernel.Get<List<int>>();

Console.WriteLine("{0}", list.Count); // 5
Console.WriteLine("{0}", result.Count); // 0, expected 5
Console.WriteLine("{0}", result == list); // False, expected True

Ninject version 3.3.4

@drieseng
Copy link
Member

drieseng commented Feb 5, 2019

This can be easily fixed (for 4.x or 5.x), but I'll need to discuss this with @scott-xu.

@JaronPiet
Copy link

Run into this issue too.

@drieseng
Copy link
Member

drieseng commented Mar 5, 2019

@pcroc @JaronPiet This is now fixed in master. As an added bonus you'll get some serious performance gains.

@Sreini
Copy link

Sreini commented Jul 16, 2020

Is there any way I can get this in my own project? The last ninject release is really old at this point and I need this fix as I had the same issue.

scott-xu pushed a commit that referenced this issue May 1, 2022
scott-xu added a commit that referenced this issue Jun 19, 2022
Resolve using standard binding resolver before resolving as a collection.
It was fixed by last commit. This commit is to remove the "Skip" instruction from unit test.

Co-Authored-By: Gert Driesen <gertdriesen@msn.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants