java.lang.Object
org.praxislive.code.userapi.Ref.Provider
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
. A custom handler must have a public,
no-arg constructor which registers initializers.invalid reference
Inject#handler()
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Ref.ProviderGet the default provider.final <T> Ref.Initializer<T> initializerFor(Class<T> type) Acquire the initializer for the given type.final booleanisSupportedType(Class<?> type) Check if this handler supports the provided type.protected final <T> voidRegister a constructor for the given type.protected final <T> voidRegister a constructor and disposer for the given type.protected final <T> voidregister(Class<T> type, Ref.Initializer<? extends T> initializer) Register an initializer to configure a Ref for the given type.The set of types supported by this handler.
-
Constructor Details
-
Provider
public Provider()Constructor. Subclasses should register initializers during construction.
-
-
Method Details
-
initializerFor
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
The set of types supported by this handler.- Returns:
- supported types
-
isSupportedType
Check if this handler supports the provided type.- Parameters:
type- type- Returns:
- supported
-
register
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- typeinitializer- initializer for type
-
provide
Register a constructor for the given type. This is a shortcut method to register an initializer, equivalent to registeringr -> r.init(constructor). The reference will use the default disposer that handlesAutoCloseable- see documentation ofRef.- Type Parameters:
T- generic type- Parameters:
type- typeconstructor- 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 registeringr -> r.init(constructor).onDispose(disposer).- Type Parameters:
T- generic type- Parameters:
type- typeconstructor- constructor for typedisposer- disposer for type
-
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
-