Annotation Type AssistFactory


Annotate a bean for which we want to generate a factory.

The bean will have some properties of normal dependency injection components and others that will be parameters to the method on the factory - these parameters are annotated with @Assisted.

Example

Create an interface for which to generate an implementation.

The factory interface must either be a functional interface, or an abstract class with only one abstract method defined.


 public interface CssFactory {

   Scanner scanner(Path myPath);
 }

 

Create a bean annotated with @AssistFactory that specifies the same factory interface. Any dependencies annotated with Assisted must be parameters of the factory method, the other dependencies will be managed and injected.

The Assisted parameters must match the factory method parameters by name and type. In this example, Path myPath match in both CssScanner and in CssFactory.


 @AssistFactory(CssFactory.class)
 class CssScanner implements Scanner {

   private final Path myPath;
   private final SomeComponent someComponent;

   CssScanner(@Assisted Path path, SomeComponent someComponent) {
     this.path = path;
     this.someComponent = someComponent;
   }

   ...
 }

 
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Specify the factory interface for which the implementation will be generated.
  • Element Details

    • value

      Specify the factory interface for which the implementation will be generated.