Skip to content

Factory and Member Injector registries

Stéphane Nicolas edited this page May 16, 2016 · 17 revisions

Both Factories and Member Injectors are generated by Toothpick annotation processors. Factories allow to create instances, whereas Member Injectors allow to assign @Inject annotated fields and call @Inject annotated methods.

FactoryRegistries and MemberInjectorRegistries allow Toothpick to retrieve the factory and member injector associated to a class C.

Setting up the registries

Toothpick generates the registries at the same time it generates the factories and member injectors. As a developer using Toothpick, you need to

  • configure the package into which the annotation processor will generate the registries for a given compilation unit (the application and each library);
  • inform the toothpick annotation processor of possible dependency of your compilation unit : toothpick will need to know where to find the registries for each of them.

Example : Simple application

Example : Application with 3 librairies

Application
 |
 + --- Lib 1
 |
 \ -+- Lib 2
    |
    \--- Lib 3

How registries work

When Toothpick create instances or inject member of instances of a class C, it needs to find the factory and member injector associated to C. Toothpick will not only look for the factory or member injector class, but also to instantiate it to use this instance (via the Factory and MemberInjector interfaces).

As Toothpick doesn't use any reflection, it needs a lookup mechanism to find the factory or member injector instance. FactoryRegistries and MemberInjectorRegistries provide this mechanism. Registries are a simple mapping of type

Each type of registry is organized in a tree. Typically the application ...

Limitation of the approach

Everything needs to be compiled with Toothpick TODO

Links