Class ReactiveContainer

java.lang.Object
page.codeberg.rrangelo.contextfx.components.Container
page.codeberg.rrangelo.contextfx.reactive.components.ReactiveContainer

public class ReactiveContainer extends Container
Reactive extension of the Container that supports ReactFX observable types as dependencies.

ReactiveContainer extends the standard container with two additional capabilities:

  • Reactive registration: reactiveRegister(Class, String) creates an instance of the class, then wraps it in the appropriate ReactFX primitive (Var, Val, or EventStream) based on the declared field/parameter type before storing it.
  • Reactive resolution: reactiveResolver(Class, String) retrieves an instance and casts it to the requested reactive type.

Generic type arguments are resolved at registration time via ParameterizedType so that the inner value type can be instantiated recursively.

Author:
Ramon Rangel Osorio <ramon.rangel@protonmail.com>
See Also:
  • Method Details

    • getReactiveInstance

      public static ReactiveContainer getReactiveInstance()
      Returns the singleton ReactiveContainer instance.
      Returns:
      the application-wide reactive container
    • getInstance

      public static ReactiveContainer getInstance()
      Convenience alias for getReactiveInstance().
      Returns:
      the application-wide reactive container
    • reactiveRegister

      public final void reactiveRegister(Class<?> clazz, String identifier)
      Creates a reactive instance of clazz, wraps it in the appropriate ReactFX primitive, and registers it under the given identifier.
      Parameters:
      clazz - the reactive class to instantiate and register
      identifier - the registration identifier; blank maps to Container.DEFAULT_IDENTIFIER
    • reactiveResolver

      public final <T> T reactiveResolver(Class<T> clazz, String identifier)
      Resolves a registered reactive component and casts it to the requested type.
      Type Parameters:
      T - the expected reactive component type
      Parameters:
      clazz - the class to resolve
      identifier - the registration identifier; blank resolves Container.DEFAULT_IDENTIFIER
      Returns:
      the registered component instance cast to T
      Throws:
      IllegalArgumentException - if the class or identifier is not registered