My question is what is best practices when registering child dependencies in a class library.
I don´t want ProjectA to know about SubClasses3 and 4
See Ioc/DI - Why do I have to reference all layers/assemblies in entry application?.
If you follow the DI pattern, there will be no "child dependencies" of your class library. Instead, the dependencies will completely (except for maybe some abstraction libraries) be reduced to a 1 to 1 relationship with your composition root in the startup application.
It is ideal for your ProjectA
application to depend on SubClasses 3 and 4
. If SubClasses 3 and 4
depend on one another or components from other libraries, you drag extra dependencies along when you use SubClass 3
or SubClass 4
.
Instead, put all of the coupling code in your composition root and no coupling code inside your application layer class libraries. This puts the application in charge of all of its dependencies.
If you have other types of class libraries, such as reusable application components, there are techniques that can be used to couple them but allow them to still be injectable. See DI-Friendly Library and DI-Friendly Framework.
NOTE: Putting all of the coupling code in your composition root doesn't necessarily mean you have to put it all in the same method or class. You can organize it across several classes and/or use conventions as in Ian's answer to make it maintainable. But at the end of the day, the application should be in charge of its dependencies, so you shouldn't move this code into other application layers - keep it in the startup layer of the application.