Annotation Type EagerInit
-
@Qualifier @Retention(CLASS) @Target({METHOD,PARAMETER,TYPE}) public @interface EagerInit
Qualifier
to use onObject
type providers to indicate the provided objects should be initialized at server startup. This is useful for dependencies used inProducerModule
because they will not be initialized until the first usage of a producer graph. ForSingleton
dependencies, it is highly recommended to provide anEagerInit
annotatedinit
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); } }