Skip to content

Factories and Member Injectors

Stéphane Nicolas edited this page May 4, 2016 · 21 revisions

In Toothpick, a Factory<Foo> is class that produces instance of Foo.

As Toothpick does not rely on reflection at all, with the idea in mind that performance is awfully slow on Android, it uses Factory classes that are generated by an annotation processor.

For which classes does Toothpick create a Factory ?

Toothpick annotation processor will create a factory for all classes that have an injected constructor :

public class Foo {
  @Inject Foo() {...}
}

Toothpick will then generate a factory :

//a simplified Factory
public final class Foo$$Factory implements Factory<Foo> {
  @Override
  public Foo createInstance() {
    return new Foo();
  }
}

Constructors with parameters

Classes with @Inject annotated fields

Factories and scopes

Factories and scope annotations

Factories and inheritance

Factories lookup

Introduce briefly and link to [Factory and MemberInjector registries].