← Back to Stormify Documentation

asDefault

Sets this instance as defaultInstance and returns it.


fun <R> asDefault(block: (Stormify) -> R): R

Runs block with this instance as the default, restoring the previous default when the block exits.

stormify.asDefault { s -> s.read<User>(...) }

Not safe under concurrent use. While the block runs, every thread that reads defaultInstance observes this instance — the override is process-wide, not thread-local. In a multi-threaded environment (e.g. a server handling parallel requests), pass the Stormify instance explicitly instead of relying on the default inside the block.