RaiiBox<T> class

A container class that wraps an instance with lifecycle management capabilities.

This class is useful for adding lifecycle management to objects that don't implement RaiiLifecycle themselves. It can execute custom initialization and disposal logic for the wrapped instance.

Example:

final connection = RaiiBox.withLifecycle(
  manager,
  instance: DatabaseConnection(),
  init: (conn, _) => conn.connect(),
  dispose: (conn, _) => conn.disconnect(),
  debugLabel: 'DbConnection',
);

// Access the wrapped instance
connection.instance.query('SELECT * FROM users');
Mixed-in types

Constructors

RaiiBox.disposable(RaiiLifecycleAware lifecycleAware, T instance, {void dispose(T)?, String? debugLabel})
Simpler factory constructor for objects that just need disposal.
factory
RaiiBox.withLifecycle(RaiiLifecycleAware lifecycleAware, {required T instance, void init(T instance, RaiiLifecycle lifecycle)?, void dispose(T instance, RaiiLifecycle lifecycle)?, String? debugLabel})
Creates a new instance and attaches it to the given lifecycleAware.

Properties

debugLabel String?
Optional label for debugging purposes.
final
dispose → void Function(T instance, RaiiLifecycle lifecycle)?
Function called to dispose of the wrapped instance.
final
hashCode int
The hash code for this object.
no setterinherited
init → void Function(T instance, RaiiLifecycle lifecycle)?
Function called to initialize the wrapped instance.
final
instance → T
The wrapped instance being managed.
final
isDisposed bool
Whether this lifecycle has been disposed.
no setterinherited
raiiHolder RaiiLifecycleAware?
The holder that manages this lifecycle.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clearRaiiHolder() → void
Clears the holder reference.
inherited
disposeLifecycle() → void
Disposes of any resources held by this object.
override
initLifecycle() → void
Initializes the lifecycle of this object.
override
isLifecycleMounted() bool
Returns whether this object's lifecycle is currently mounted.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setRaiiHolder(RaiiLifecycleAware holder) → void
Sets the holder for this lifecycle.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited