Annotation Interface Factory


A factory is a Singleton that produces one or many other bean implementations.

Each produced bean is defined by method that is annotated with Bean

 @Factory
 public class MyFactory {

     @Bean
     public MyBean myBean() {
         // create the bean
     }
 }

Methods defined within the body of the class that are annotated with Bean will be exposed as beans.

You can use a Scope annotation to control the scope the bean is exposed within. For example for a singleton instance you can annotate the method with Singleton.

Methods annotated with Bean can accept arguments and Micronaut will attempt to inject those arguments from existing beans or values. For example:

 @Factory
 public class MyFactory {

     @Bean
     public MyBean myBean(@Value("foo.bar") String myValue) {
         // create the bean
     }
 }
Since:
1.0
Author:
Graeme Rocher
See Also: