Annotation Type Bind


  • @Target(TYPE)
    @Retention(RUNTIME)
    @Documented
    @Inherited
    public @interface Bind
    This annotation makes the class on which it is applied, injectable. In the basic case, the class will be injectable with its own type:
     @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.

    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element 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.
    • Element Detail

      • from

        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). If not specified, the implementation will be bound to itself, meaning that it will be injectable directly. When this parameter is specified, a qualifier annotation can optionally be applied on the implementation to define a qualifier key.
        Returns:
        the class to be used as injection key.
        Default:
        java.lang.Object.class
      • 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