Skip to content

Injection site discovery

Andy Boothe edited this page Jan 1, 2025 · 1 revision

Rapier searches for injection sites in the following ways:

  1. Start at a @Component-annotated class ("component")
  2. Visit each provision method in the component, or any superclasses or superinterfaces. Each one is an injection site, with the return type of the method as the provisioned type.
  3. For each @Module-annotated class ("module") in the @Component(modules) attribute, continue to step 4.
  4. For each instance and static @Provides-annotated method in the module or its superclasses, visit each parameter in the method. Each one is an injection site, with the type of the parameter as the provisioned type.
  5. For each @Module-annotated class in the @Module(includes) attribute, continue to step 4. Ensure that no module is visited more than once.
  6. For the type of each injection site, continue to step 7.
  7. If the type is primitive, move on to the next type.
  8. If the type is an interface or abstract class, move on to the next type.
  9. For the sole @Inject-annotated constructor in the type, if it exists, visit each parameter in the constructor. Each one is an injection site, with the type of the parameter as the provisioned type. Nominate the type to restart at step 6.
  10. For each @Inject-annotated method in the type, visit the sole parameter in the method. It is an injection site, with the type of the parameter as the provisioned type. Nominate the type to restart at step 6.
  11. For each @Inject-annotated field in the type, visit the field. It is an injection site, with the type of the parameter as the provisioned type. Nominate the type to restart at step 6.
  12. Repeat for each type, starting at step 6. Ensure that no type is visited more than once.

Only fully-resolved generic types are visited, throughout.

Clone this wiki locally