@Target(value=TYPE) @Retention(value=RUNTIME) @Documented @Inherited public @interface Provide
Provider
. It is
comparable to the Bind
annotation but allow to specify the creation logic of the instance in the
Provider.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 Provide
annotation allows to override any existing SeedStack binding. To do this,
create a Provider
producing the same type as the SeedStack binding you want to override (this is the type
you use at the injection point) and set the override()
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.
Modifier and Type | Optional Element and Description |
---|---|
boolean |
override
If true the binding will be defined as an overriding one, meaning that it will override an identical binding
already defined.
|
public abstract boolean override
Copyright © 2013-2018–2019 SeedStack. All rights reserved.