1

I started using Ninject for my project, to automatically bind all subclasses of an abstract class. The binding for this is -- nice and easy -- as follows:

kernel.Bind(x => x.FromThisAssembly()
    .SelectAllClasses().
    .InheritedFrom<AbstractGenerator>()
    .BindBase());

However, I found that this doesn't work. After some experimenting I found that the reason for this not working is that all my implementations (and the abstract class) are marked internal.

I could imagine this to be some security feature, to prevent bindings from leaking internals to the outside. But I can add explicit bindings for these classes. Hence, my question is: Does anybody know whether this is intended behavior? Is there some way to fix this, other than making all my classes public?

Sven Amann
  • 565
  • 2
  • 12

1 Answers1

7

Put a .IncludingNonPublicTypes() before the .SelectAllClasses() and your bindings will also work for internal classes.

Also see this question: Cannot get Ninject.Extensions.Conventions to work

I don't think it's about security. I guess it's about design and maybe about performance: choosing from only the public types takes less time than choosing from all types.

LeopardSkinPillBoxHat
  • 28,915
  • 15
  • 75
  • 111
BatteryBackupUnit
  • 12,934
  • 1
  • 42
  • 68
  • Thanks, this was what I was looking for. Only that I search for the quantification after SelectAllClasses(), because that's where all the other quantification happens... Sorry about the duplicate, but I failed to find this other post... – Sven Amann Oct 11 '13 at 14:56