@Target(value=TYPE) @Retention(value=RUNTIME) @Documented @Inherited public @interface Bind
@Bind public class SomeImplementation {...} @Inject SomeImplementation someImplementation;
If an injection class is specified with from()
, the implementation will be injectable with the specified
type instead:
@Bind(from = SomeInterface.class) public class SomeImplementation implements SomeInterface {...} @Inject SomeInterface someInterface;
The Bind
annotation allows to override any interface-based SeedStack binding. To do this,
create a custom implementation of the SeedStack interface you want to customize (this is the type you use at the
injection point) and set the override()
boolean to true. Your custom implementation 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 |
---|---|
Class<?> |
from
If specified, this class will be used as the binding key, meaning that the implementation will be injectable
through this class only (from which the implementation must be assignable).
|
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 Class<?> from
public abstract boolean override
Copyright © 2013-2018–2019 SeedStack. All rights reserved.