First, we should limit the creation of the module to a single site in our system, in this case, the newInstance method within the module configuration. This ensures we always assemble the module with the same logic.
After that, we can create a similar instantiation method but that allows us to inject mocks. Use fakes whenever possible (like InMemory Hashmap implementations of repositories). Mocks should be limited to references to other modules to test the interaction between them. Or to an eventPublisher to test that the expected events where sent.
In this gist you will find examples of how to write these configuration files.