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>jakarta.inject.Provider</code> Factory and Bean provide 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. The expectation is that we tend to use Factory and Bean 018 * rather than Provider. 019 * </p> 020 * 021 * <pre>{@code 022 * 023 * @Factory 024 * class Configuration { 025 * 026 * private final StartConfig startConfig; 027 * 028 * @Inject 029 * Configuration(StartConfig startConfig) { 030 * this.startConfig = startConfig; 031 * } 032 * 033 * @Bean 034 * Foo buildFoo() { 035 * ... 036 * return new Foo(...); 037 * } 038 * 039 * @Bean 040 * Bar buildBar(Foo foo, Bazz bazz) { 041 * ... 042 * return new Bar(...); 043 * } 044 * } 045 * }</pre> 046 */ 047@Target(ElementType.TYPE) 048@Retention(RetentionPolicy.RUNTIME) 049public @interface Factory { 050}