Open toddliebenschutz-jones opened 1 year ago
Hey @toddliebenschutz-jones , letting you know since you may be targeting Guice 7.0.0, about the new Micronaut Guice project, that depending on your usecase could be a useful replacement: https://github.com/micronaut-projects/micronaut-guice/issues/9
When using nested Guice injectors, the exception message makes it look like any error in the inner injector is occurring in the outer injector.
Example 1
In this code, each test attempts to create a Guice injector that cannot be created.
createNonNestedModule
creates a Guice injector with a missing dependencycreateNestedModule
creates a Guice injector whose only moduleModuleWithNestedGuiceInjector
throws when created. This moduleModuleWithNestedGuiceInjector
throws because it creates a nested Guice injector with a missing dependency.These two failures are from two fundamentally different Guice injectors failing to start up (i.e. the nested injector, or the outer injector), however the exception message does not allow them to be distinguished.
Non-nested exception message
``` Unable to create injector, see the following errors: 1) [Guice/MissingImplementation]: No implementation for DemoTest$MyInterface was bound. Requested by: 1 : DemoTest$MyClass.Nested exception message
``` Unable to create injector, see the following errors: 1) [Guice/MissingImplementation]: No implementation for DemoTest$MyInterface was bound. Requested by: 1 : DemoTest$MyClass.Example 2
The second example shows why this is confusing in practice. The exception message does not allow the user to work out which injector has the missing dependency. The exception messages for these two test are the same (apart from the test method in the stack trace).
Exception message
``` Unable to create injector, see the following errors: 1) [Guice/MissingImplementation]: No implementation for DemoTest$MyInterface was bound. Requested by: 1 : DemoTest$MyClass.Other notes