Package org.seedstack.seed
Annotation Type Provide
-
@Target(TYPE) @Retention(RUNTIME) @Documented @Inherited public @interface Provide
This annotation creates an injection binding when applied on a JSR-330Provider. It is comparable to theBindannotation but allow to specify the creation logic of the instance in theProvider.get()method. A provider is itself injectable so you can use any required dependency during the creation of the provided instance.@Provide public class Provider<SomeClass> { @Inject private SomeDependency someDependency; public SomeInterface get() { return new SomeClass(someDependency); } } @Inject SomeClass someClassInstance;The
Provideannotation allows to override any existing SeedStack binding. To do this, create aProviderproducing the same type as the SeedStack binding you want to override (this is the type you use at the injection point) and set theoverride()boolean to true. The instance produced by your provider will replace the SeedStack one.When a qualifier annotation is present on the implementation class, it is used to make the injection point more specific:
@Qualifier @Retention(RetentionPolicy.RUNTIME) public interface @SomeQualifier {...} @Bind(from = SomeInterface.class) @SomeQualifier public class SomeImplementation implements SomeInterface {...} @Inject @SomeQualifier SomeInterface someInterface;When having multiple implementations of the same interface, using a different qualifier on each implementation allows to create multiple bindings. You can then choose the implementation by specifying the corresponding qualifier at injection point.
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description booleanoverrideIf true the binding will be defined as an overriding one, meaning that it will override an identical binding already defined.
-
-
-
Element Detail
-
override
boolean override
If true the binding will be defined as an overriding one, meaning that it will override an identical binding already defined. If false, the binding will defined as a normal one.- Returns:
- if true the binding is an overriding binding, if false a normal binding.
- Default:
- false
-
-