Annotation Interface ProductionComponent


@Retention(RUNTIME) @Documented @Target(TYPE) @Beta public @interface ProductionComponent
Annotates an interface or abstract class for which a fully-formed, dependency-injected implementation is to be generated from a set of modules. The generated class will have the name of the type annotated with @ProductionComponent prepended with Dagger. For example, @ProductionComponent interface MyComponent {...} will produce an implementation named DaggerMyComponent.

Each Produces method that contributes to the component will be called at most once per component instance, no matter how many times that binding is used as a dependency. TODO(beder): Decide on how scope works for producers.

Component methods

Every type annotated with @ProductionComponent must contain at least one abstract component method. Component methods must represent production.

Production methods have no arguments and return either a ListenableFuture or Producer of a type that is injected, provided, or produced. Each may have a Qualifier annotation as well. The following are all valid production method declarations:


   ListenableFuture<SomeType> getSomeType();
   Producer<Set<SomeType>> getSomeTypes();
   @Response ListenableFuture<Html> getResponse();
 

Exceptions

When a producer throws an exception, the exception will be propagated to its downstream producers in the following way: if the downstream producer injects a type T, then that downstream producer will be skipped, and the exception propagated to its downstream producers; and if the downstream producer injects a Produced<T>, then the downstream producer will be run with the exception stored in the Produced<T>.

If a non-execution exception is thrown (e.g., an InterruptedException or CancellationException), then exception is handled as in Futures.transform(com.google.common.util.concurrent.ListenableFuture<I>, com.google.common.base.Function<? super I, ? extends O>, java.util.concurrent.Executor).

Executor

The component must include a binding for @Production Executor; this binding will be called exactly once, and the provided executor will be used by the framework to schedule all producer methods (for this component, and any ProductionSubcomponent it may have.

Since:
2.0
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static @interface 
    A builder for a production component.
    static @interface 
    A factory for a production component.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Class<?>[]
    A list of types that are to be used as component dependencies.
    Class<?>[]
    A list of classes annotated with Module or ProducerModule whose bindings are used to generate the component implementation.
  • Element Details

    • modules

      Class<?>[] modules
      A list of classes annotated with Module or ProducerModule whose bindings are used to generate the component implementation.
      Default:
      {}
    • dependencies

      Class<?>[] dependencies
      A list of types that are to be used as component dependencies.
      Default:
      {}