Turn off self binding

105 views
Skip to first unread message

Rob A'Court

unread,
May 15, 2013, 11:22:48 AM5/15/13
to nin...@googlegroups.com
Hi

Is there any way to get the ninject kernel to throw an exception if it is asked to resolve a class that has no bindings?

It already does this for interfaces but if you ask it to resolve a class it will conclude that it is self-bindable and so not throw an exception. We've had a few bugs now caused by us forgetting to set up the binding, for instance it might need to be in singleton scope and without the binding we'll get many instances.

Any ideas?

Many thanks

Rob


Ian Davis

unread,
May 15, 2013, 11:38:30 AM5/15/13
to ninject
I think you can derive from StandardKernel and override "protected virtual bool HandleMissingBinding(IRequest request){...}" to just return false.

-Ian



Rob


--
You received this message because you are subscribed to the Google Groups "ninject" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ninject+u...@googlegroups.com.
To post to this group, send email to nin...@googlegroups.com.
Visit this group at http://groups.google.com/group/ninject?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Bartelink, Ruben

unread,
May 15, 2013, 5:50:13 PM5/15/13
to nin...@googlegroups.com
IIRC there's an AllowImplicitSelfBinding on NinjectSettings
--
--Ruben
Ruben Bartelink / +353 86 885 2399

Ian Davis

unread,
May 15, 2013, 5:55:20 PM5/15/13
to ninject
As far as I see at the moment, there is no such option. Neither in the settings nor the kernel.

-Ian

Bartelink, Ruben

unread,
May 15, 2013, 6:10:12 PM5/15/13
to nin...@googlegroups.com
Doh, I used to know that too = you're right of course as usual!


Thinking about it, I think it's an important thing to be able to control easily. Having said that, I like using stuff in no-surprises OOTB mode where possible, regardless of whether I agree with the merits of individual marginal decisions.

--R

Remo Gloor

unread,
May 16, 2013, 2:05:24 AM5/16/13
to nin...@googlegroups.com

Rob A'Court

unread,
May 20, 2013, 6:20:36 AM5/20/13
to nin...@googlegroups.com
We've gone with the following solution for now and that seems to work perfectly:

kernel.Components.RemoveAll<IMissingBindingResolver>();
kernel.Components.Add<IMissingBindingResolver, DefaultValueBindingResolver>();
Thanks for everyone's help!

To unsubscribe from this group and stop receiving emails from it, send an email to ninject+unsubscribe@googlegroups.com.


To post to this group, send email to

Reply all
Reply to author
Forward
0 new messages