Troubleshoot Missing or Circular Dependencies
Identifying Injection Problems
When the injector can't create an instance, it usually means a dependency is missing or there's a circular reference where Class A needs Class B, and Class B needs Class A.
Fixing Missing Dependencies
1. Verify annotations — ensure all classes you're injecting have @ImplementedBy or are bound in a custom module.
2. Check the dependency chain — trace what each class needs. If a dependency isn't annotated or bound, add it.
3. Use custom modules for complex cases where automatic annotation doesn't work.
Resolving Circular Dependencies
1. Refactor your design — circular dependencies usually mean classes have too many responsibilities. Split them or introduce an intermediate service.
2. Use lazy injection — if available, inject a provider instead of the class directly. This delays instantiation and can break cycles.
3. Check your bindings — in custom modules, ensure you're not accidentally creating a loop through your binding definitions.
If problems persist, review your mod's architecture to ensure dependencies flow in one direction.