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

Factory extension silently binds Func<...> #21

Open
l3m opened this issue Jul 21, 2014 · 0 comments
Open

Factory extension silently binds Func<...> #21

l3m opened this issue Jul 21, 2014 · 0 comments

Comments

@l3m
Copy link

l3m commented Jul 21, 2014

In our code, we had a really weird bug related to Ninject, and according to this stackoverflow answer, the root cause was that the Ninject Factory extension bind Func<T,T,bool> (and possibly other Funcs).

Assume an object such as

public class PriorityQueue<T>(Func<T,T,bool> cmp_func) : IPriorityQueue<T>
{ ... } 

and a Factory

public IPriorityQueueFactory 
{
    IPriorityQueue<T> Create<T>();
} 

The expected behavior would be that Ninject will throw an exception, because the constructor argument was not bound. But this will not happen; instead, the factory extension will silently inject the non-user-bound Func<...>.

This is very confusing, and it cost me a long time to track down the bug.

I would assume that for most users, silently adding bindings for something as common as a Func<...> is outside of the expected behavior of a ninject extension.

The problem gets even worse if using custom factories as explained here. Then the bug occurs if the factory extension is in the usings, but behaves correctly otherwise.

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

No branches or pull requests

1 participant