When using Dependency Injection across internal classes (implementation details) in a library which is to be consumed by multiple applications, is there a good way to configure the IOC container?
From my understanding, the canonical way of doing this in a regular program is by setting up the dependencies at the “Composition Root” such as the main method. But this approach cannot be taken for a library (consumed by applications with their own composition roots), especially if the library has a large public API with many entries points.
Is the best way to wire dependencies in this instance while still allowing unit testing (as opposed to integration testing) of the public API to use a ServiceLocator and provide some mechanism for mocking the ServiceLocator? Note that all dependencies themselves could still use constructor injection, but the top level public API would have to use a ServiceLocator to resolve the top level dependencies.
What if there is a single entry point to the library (but it would still be good to unit test that entry point), does that change the answer?