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 which we want avaje-inject to generate an implementation. We desire this
because the factory has some managed dependencies that should be injected for us and some
dependencies that are provided by the application (and annotated with Assisted).
The factory supertype must 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 factory. Any
dependencies that are annotated with Assisted will be parameters of the factory method,
the other dependencies will be managed and injected by avaje-inject.
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
-
Element Details
-
value
Specify the factory interface for which the implementation will be generated.
-