Package dev.relism.flash.extension
Class FlashContext
java.lang.Object
dev.relism.flash.extension.FlashContext
Central service registry and boot-time hook coordinator.
Every handler, extension, and scope shares one (or a child of one) FlashContext.
Three capabilities:
- Service registry —
provide(java.lang.Class<T>, T)/supply(java.lang.Class<T>, java.util.function.Supplier<T>)/require(java.lang.Class<T>)/find(java.lang.Class<T>). - Annotation processors — middleware injection from handler annotations at boot.
- Route listeners — boot-time observation of the route graph.
Eager vs lazy registration
provide(Class, Object)— instance is already constructed, registered immediately.supply(Class, Supplier)— factory is registered; it runs once, atresolveAll()time (called byFlashApp.start()) after allFlashExtension.provide(dev.relism.flash.extension.FlashContext)phases complete. The factory may callrequire(java.lang.Class<T>)for its own dependencies — the runtime resolves in topological order automatically and reports circular dependencies with the full cycle path.
A child context (via child()) inherits parent services and processors.
Services provided on the child are scoped and invisible to the parent.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAnnotationProcessor(AnnotationProcessor processor) Registers anAnnotationProcessor.voidaddRouteListener(RouteListener listener) Registers a boot-timeRouteListener.child()Creates a child context that inherits this context's services and processors.<T> Optional<T> Returns the service fortype, or empty if not found in this scope or any parent.<T> Optional<T> Alias forfind(java.lang.Class<T>)— prefer when semantics are "this may or may not exist".<T> voidRegisters an already-constructedinstanceundertype.<T> TReturns the service fortype.<T> voidRegisters a lazy factory fortype.
-
Constructor Details
-
FlashContext
public FlashContext()
-
-
Method Details
-
child
Creates a child context that inherits this context's services and processors. -
provide
Registers an already-constructedinstanceundertype. -
supply
Registers a lazy factory fortype. The factory runs once atresolveAll()time (or on the firstrequire(java.lang.Class<T>)call for this type) and may callrequire(java.lang.Class<T>)for its own dependencies — topological order is resolved automatically.ctx.supply(JwtValidator.class, () -> new JwtValidator(ctx.require(OidcProviderMetadata.class).jwksUri())); -
require
Returns the service fortype. Checks own scope first, then parent chain. Lazy-registered types are resolved on first access. Circular dependencies throwIllegalStateExceptionwith the full cycle path.- Throws:
IllegalStateException- if the service is not found anywhere in the context chain
-
find
Returns the service fortype, or empty if not found in this scope or any parent. -
optional
Alias forfind(java.lang.Class<T>)— prefer when semantics are "this may or may not exist". -
addAnnotationProcessor
Registers anAnnotationProcessor. Processors run once per class-based handler at boot. -
addRouteListener
Registers a boot-timeRouteListener. Zero overhead on the request hot-path.
-