Class FlashContext

java.lang.Object
dev.relism.flash.extension.FlashContext

public final class FlashContext extends Object
Deterministic boot-time service graph, frozen before handlers are initialised.
  • Constructor Details

    • FlashContext

      public FlashContext()
  • Method Details

    • child

      public FlashContext child()
    • provide

      public <T> void provide(Class<T> type, T instance)
      Binds an already-created singleton. Duplicate bindings are always an error.
    • override

      public <T> void override(Class<T> type, T instance)
      Replaces the binding for type, whether or not one already exists.

      The declaration rule everywhere else is that a duplicate is an error (provide(java.lang.Class<T>, T), supply(java.lang.Class<T>, java.util.function.Supplier<T>)); this is the single deliberate exception, and it exists for tests — flash-testing installs overrides as the last extension so a fake wins over whatever the application or an extension declared. Using it in production code is legal but almost always a mistake, so a replacement is logged.

    • supply

      public <T> void supply(Class<T> type, Supplier<T> factory)
      Declares a no-dependency boot factory.
    • supply

      public <T> void supply(Class<T> type, FlashContext.ServiceFactory<T> factory, Class<?>... dependencies)
      Declares a boot factory and its complete dependency set.
    • supply

      public <A, T> void supply(Class<T> type, Class<A> dependency, Function<A,T> factory)
      One-dependency factory with no application-side context lookup.
    • onReady

      public void onReady(Runnable callback)
      Registers work materialised after all services are resolved.
    • onClose

      public void onClose(Runnable callback)
      Registers cleanup to run when the app stops, after in-flight requests have drained.

      Deliberately callable outside DECLARING so a factory can register its own teardown while it is being resolved:

      
       ctx.supply(DataSource.class, c -> {
           HikariDataSource ds = new HikariDataSource(cfg);
           c.onClose(ds::close);
           return ds;
       });
       
    • require

      public <T> T require(Class<T> type)
    • find

      public <T> Optional<T> find(Class<T> type)
    • optional

      public <T> Optional<T> optional(Class<T> type)
    • addAnnotationProcessor

      public void addAnnotationProcessor(AnnotationProcessor processor)
    • addRouteListener

      public void addRouteListener(RouteListener listener)
    • complete

      public void complete()
      Completes graph resolution and runs all deferred materialisation callbacks once.