Class Ref.Provider

  • Enclosing class:
    Ref<T>

    public abstract static class Ref.Provider
    extends Object
    Providers initialize Ref instances so that the underlying value can be used directly as the injected field type.

    A default provider covers some basic types, or a custom handler type may be set in Inject#handler(). A custom handler must have a public, no-arg constructor which registers initializers.

    • Constructor Detail

      • Provider

        public Provider()
        Constructor. Subclasses should register initializers during construction.
    • Method Detail

      • initializerFor

        public final <T> Ref.Initializer<T> initializerFor​(Class<T> type)
        Acquire the initializer for the given type.
        Type Parameters:
        T - generic type
        Parameters:
        type - type
        Returns:
        initializer for type, or null if not supported
      • supportedTypes

        public final Set<Class<?>> supportedTypes()
        The set of types supported by this handler.
        Returns:
        supported types
      • isSupportedType

        public final boolean isSupportedType​(Class<?> type)
        Check if this handler supports the provided type.
        Parameters:
        type - type
        Returns:
        supported
      • register

        protected final <T> void register​(Class<T> type,
                                          Ref.Initializer<? extends T> initializer)
        Register an initializer to configure a Ref for the given type. The initializer should initialize the Ref, as well as add dispose or other handlers as required.
        Type Parameters:
        T - generic type
        Parameters:
        type - type
        initializer - initializer for type
      • provide

        protected final <T> void provide​(Class<T> type,
                                         Supplier<? extends T> constructor)
        Register a constructor for the given type. This is a shortcut method to register an initializer, equivalent to registering r -> r.init(constructor). The reference will use the default disposer that handles AutoCloseable - see documentation of Ref.
        Type Parameters:
        T - generic type
        Parameters:
        type - type
        constructor - constructor for type
      • provide

        protected final <T> void provide​(Class<T> type,
                                         Supplier<? extends T> constructor,
                                         Consumer<? super T> disposer)
        Register a constructor and disposer for the given type. This is a shortcut method to register an initializer, equivalent to registering r -> r.init(constructor).onDispose(disposer).
        Type Parameters:
        T - generic type
        Parameters:
        type - type
        constructor - constructor for type
        disposer - disposer for type
      • getDefault

        public static Ref.Provider getDefault()
        Get the default provider. The default provider supports fields of type List, Map and Set, via ArrayList, LinkedHashMap and LinkedHashSet respectively.
        Returns:
        default provider