Canvas

Resolved dependencies and locally owned resources for Mosaic.

Provides a mechanism to retrieve dependencies by their class type. This is used internally by the Mosaic class to support dependency injection in DSL tile functions. Construct a Canvas with canvas or withLayer.

Functions

Link copied to clipboard
open override fun close()

Closes locally owned AutoCloseable resources once in reverse successful creation order. Closing is synchronous, idempotent, and safe under concurrent callers. One caller performs cleanup; other callers wait for it to finish and return without repeating cleanup or failures. Reentrant calls from a resource's close hook return without repeating cleanup.

Link copied to clipboard
fun <T : Any> source(key: CanvasKey<T>): T

Retrieves a dependency identified by CanvasKey

fun <T : Any> source(type: KClass<T>, qualifier: String? = null): T

Retrieves a dependency of the specified type and qualifier

Link copied to clipboard
fun <T : Any> sourceOrNull(key: CanvasKey<T>): T?

Retrieves an instance under CanvasKey, checking explicit local and ancestor bindings before the optional CanvasDependencyResolver. Returns null only when absent; resolver ambiguity, creation and scope failures propagate.

fun <T : Any> sourceOrNull(type: KClass<T>, qualifier: String? = null): T?

Retrieves an instance of the registered object Returns null if the object isn't found

Link copied to clipboard
suspend fun withLayer(build: CanvasBuilder.() -> Unit): Canvas

A DSL method to create another layer on your Canvas The returned object will be a new Canvas depending on the sources of the parent This does not modify the parent in any way. Child bindings are constructed eagerly; a child constructor can use CanvasFactory.source to resolve local bindings first and then fall back to the parent. Child overrides do not rewire services already created by the parent.

Inherited functions

Link copied to clipboard
inline fun <T : Any> Canvas.source(qualifier: String? = null): T

Inline extension function to retrieve a dependency using reified type parameters.

Link copied to clipboard
inline fun <T : Any> Canvas.sourceOrNull(qualifier: String? = null): T?

Inline extension function to retrieve a dependency using reified type parameters. Returns null if the source is not found.

Link copied to clipboard
suspend fun <R> Canvas.withMosaic(block: suspend Mosaic.() -> R): R

Executes block with a request-owned Mosaic, inheriting the calling coroutine's context. Tile producers are supervised siblings: cancelling a waiter does not cancel shared work. Request cancellation cancels unfinished producers. Every exit cancels speculative work and waits for producer and attached-child cleanup before returning or propagating the block's failure. Each invocation has a fresh cache. Keep the complete handler inside block; do not retain its Mosaic for later requests. This function does not close this Canvas. Scope a child Canvas separately when it constructs owned resources.