Enum TypeDependency.Kind

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<TypeDependency.Kind>
    Enclosing class:
    TypeDependency

    public static enum TypeDependency.Kind
    extends java.lang.Enum<TypeDependency.Kind>
    Enumerates how a type will be injected at a particular injetion site
    Author:
    cdivilly
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      MULTIPLE
      All available implementations of the type (matching the TypeQualifier) are injected
      OPTIONAL
      The dependency is injected if available, otherwise a null value is supplied.
      PROVIDER
      The dependency is injected via a Provider instance, resolving of the dependency is deferred until Provider.get() is invoked.
      REQUIRED
      The default injection kind, one instance of the required dependency must be available or else instantiation of the type is abandoned and TypeDependencyNotAvailableException is raised
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static TypeDependency.Kind valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static TypeDependency.Kind[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • MULTIPLE

        public static final TypeDependency.Kind MULTIPLE
        All available implementations of the type (matching the TypeQualifier) are injected
         @Inject 
         SomeType(final Iterable<SomeOtherType> providers) {
           ...
         }
         
        • The injection site uses a parameterized Iterable declaration to receive all matching instance
        • Matching types which cannot be instantiated because their onward dependencies are unresolvable are silently omitted from the set of matches
        • If no matches are available an empty Iterable is injected
      • OPTIONAL

        public static final TypeDependency.Kind OPTIONAL
        The dependency is injected if available, otherwise a null value is supplied. Cannot be used for primitive type injections, MULTIPLE or PROVIDER injections
         @Inject 
         SomeType(final @Optional SomeOtherType provider) {
           ...
         }
         
        • The injection site uses the Optional annotation to indicate the dependency is optional
      • PROVIDER

        public static final TypeDependency.Kind PROVIDER
        The dependency is injected via a Provider instance, resolving of the dependency is deferred until Provider.get() is invoked. This can be used for lazy initialization and to break cyclic dependencies
         @Inject 
         SomeType(final Provider<SomeOtherType> provider) {
           ...
         }
         
        • The injection site uses a parameterized Provider declaration to receive the matching Provider
      • REQUIRED

        public static final TypeDependency.Kind REQUIRED
        The default injection kind, one instance of the required dependency must be available or else instantiation of the type is abandoned and TypeDependencyNotAvailableException is raised
         @Inject 
         SomeType(final SomeOtherType provider) {
           ...
         }
         
        • The injection site uses the Optional annotation to indicate the dependency is optional
    • Method Detail

      • values

        public static TypeDependency.Kind[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (TypeDependency.Kind c : TypeDependency.Kind.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static TypeDependency.Kind valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null