Skip to content

Function: OnProvision() ​

ts
function OnProvision(): LifecycleDecorator<ProvisionHook>;

Defined in: src/wirestate-core/provision/on-provision.ts:54

Runs when a framework provider exposes the container.

Returns ​

LifecycleDecorator<ProvisionHook>

Method decorator.

Remarks ​

React and Lit providers call this when a container enters a UI subtree. This is provider lifetime, not instance lifetime.

Use it for subscriptions, timers, sockets, observers, provider-scoped async work, or any resource that should be cleaned up when the provider releases the container. A class hierarchy may have one provision hook name.

Hooks run in creation order, so a service can rely on the dependencies it injected having provisioned already. @OnDeprovision unwinds the exact reverse.

Example ​

typescript
import { Injectable, OnProvision } from "@wirestate/core";

@Injectable()
class PanelService {
  @OnProvision()
  public onProvision(): void {
    this.startPolling();
    this.connect();
  }
}