Annotation Type EagerInit


  • @Qualifier
    @Retention(CLASS)
    @Target({METHOD,PARAMETER,TYPE})
    public @interface EagerInit
    Qualifier to use on Object type providers to indicate the provided objects should be initialized at server startup. This is useful for dependencies used in ProducerModule because they will not be initialized until the first usage of a producer graph. For Singleton dependencies, it is highly recommended to provide an EagerInit annotated init provider that accepts the objects as dependencies.

    For example,

    
     {@literal @}Module
     public class MyModule {
       {@literal @}Provides
       {@literal @}Singleton
       public Database slowDatabase() {
         return Database.connect();
       }
    
       {@literal @}Provides
       {@literal @}Singleton
       public ServerConfig serverConfig(Config config) {
         return config.load("server");
       }
    
       {@literal @Provides}
       {@literal @ElementsIntoSet}
       {@literal @EagerInit}
       public Set<Object> init(Database database, ServerConfig config) {
         return ImmutableSet.of(database, config);
       }
     }