7

I have just started using StructureMap, having previously worked with Spring.Net. I love the DefaultConventionScanner and the ability to scan assemblies and use convention over configuration to find classes. But there seems to be a limitation that the classes that implement the interfaces must be public, whereas we like to keep out interfaces public and our implementations internal to an assembly.

Is there a way to ask the DefaultConventionScanner to find internal classes as well?

Colin Desmond
  • 4,824
  • 4
  • 46
  • 67

1 Answers1

11

No, and in fact the limitation that classes should be public applies to all of StructureMap - not just the convention scanners. You can register internal types manually with StructureMap if you make use of the InternalsVisibleTo attribute, but it is not well-supported or documented. You will not be able to make an ITypeScanner (like DefaultConventionScanner) that registers internal types because the AssemblyScanner only exposes exported types.

Joshua Flanagan
  • 8,527
  • 2
  • 31
  • 40
  • Noting that this answer is several years old...is this still the case? – Sam Storie Feb 16 '15 at 12:52
  • Yes, it is still the case. "Behind the scenes, StructureMap is using the Assembly.GetExportedTypes() method from the .Net CLR to find types and ... " - http://structuremap.github.io/registration/auto-registration-and-conventions/ – Mattias Nordqvist Aug 02 '16 at 08:38
  • Just to drop an update here (having this question myself): in 4.7.1 it seems that Scan() is still limited to public types, but it is possible to manually register an internal class implementing a public interface, and even an internal class implementing an internal interface. – avat Feb 05 '20 at 17:53