take method
Takes ownership of a lifecycle from its current owner.
Detaches the lifecycle from its current owner (if any) without disposing it, then registers it with this container. The lifecycle remains mounted throughout the transfer.
This is useful when a resource needs to outlive its original owner and be managed by a different lifecycle container.
Throws NotInitializedException if the lifecycle has not been initialized.
Example:
final ownerA = RaiiManager()..initLifecycle();
final ownerB = RaiiManager()..initLifecycle();
final resource = RaiiBox.withLifecycle(
ownerA,
instance: MyResource(),
dispose: (r) => r.cleanup(),
);
// Move resource from ownerA to ownerB
ownerB.take(resource);
ownerA.disposeLifecycle(); // resource is NOT disposed
ownerB.disposeLifecycle(); // resource IS disposed
Implementation
@override
void take(RaiiLifecycle lifecycle) {
_raiiManager.take(lifecycle);
}