001package io.avaje.inject;
002
003import java.lang.annotation.ElementType;
004import java.lang.annotation.Retention;
005import java.lang.annotation.RetentionPolicy;
006import java.lang.annotation.Target;
007
008/**
009 * A singleton bean that has methods marked with the <code>@Bean</code> annotation.
010 * <p>
011 * Factory beans allow us to build beans using logic in methods. These methods for example
012 * often use environment variables and system properties into account when building the bean.
013 * </p>
014 * <p>
015 * Relative to <code>javax.inject.Provider</code>, Factory and Bean provides a more flexible
016 * approach that allows dependencies on the method (as method parameters) as well as multiple
017 * methods on the single factory bean.
018 * </p>
019 *
020 * <pre>{@code
021 *
022 * @Factory
023 * class Configuration {
024 *
025 *   private final StartConfig startConfig;
026 *
027 *   @Inject
028 *   Configuration(StartConfig startConfig) {
029 *     this.startConfig = startConfig;
030 *   }
031 *
032 *   @Bean
033 *   Foo buildFoo() {
034 *     ...
035 *     return new Foo(...);
036 *   }
037 *
038 *   @Bean
039 *   Bar buildBar(Foo foo, Bazz bazz) {
040 *     ...
041 *     return new Bar(...);
042 *   }
043 * }
044 * }</pre>
045 */
046@Target(ElementType.TYPE)
047@Retention(RetentionPolicy.SOURCE)
048public @interface Factory {
049}