Skip to content

Interface: WirestatePlugin ​

Defined in: src/wirestate-core/plugin/plugin.ts:38

A container lifecycle plugin.

Remarks ​

Register plugins on a Container via config.plugins. A plugin is a class instance, so it can hold per-instance state, and every hook is optional.

Plugins bracket the user layer (@OnActivation / @OnProvision): setup hooks run before the matching user hook, teardown hooks run after it. Setup hooks (install, onActivate, onContainerProvision, onProvision) are atomic, so a throw unwinds the activation/provision cycle. Teardown hooks (onDeactivate, onDeprovision, onContainerDeprovision) and disposers are failsafe, so a throw is swallowed and teardown continues. Plugin teardown failures are not reported through the container error handler.

A plugin reaches its container and every descendant (plugins resolve up the parent chain, nearest first), so one registered on the root observes the whole subtree unless a nearer built-in messaging plugin shadows the same kind.

Example ​

typescript
import { Container, WirestatePlugin } from "@wirestate/core";

class LogPlugin implements WirestatePlugin {
  public onActivate(instance: object): void {
    console.log("activated", instance.constructor.name);
  }
}

new Container({ plugins: [new LogPlugin()] });

Methods ​

install()? ​

ts
optional install(container: Container, addRollback: (rollback: () => void) => void): void;

Defined in: src/wirestate-core/plugin/plugin.ts:53

Contributes bindings (or other one-time setup) when the plugin is registered.

Parameters ​

ParameterTypeDescription
containerContainerContainer the plugin is registered on.
addRollback(rollback: () => void) => voidRegisters cleanup for a failed container construction.

Returns ​

void

Remarks ​

Runs once, on the container the plugin is registered on (not on inheriting children), before any binding activates.

Register cleanup for install-time side effects with addRollback. Rollbacks run in reverse order if this or a later install throws, or if container construction fails afterwards. They are failsafe and do not run during normal container teardown.


onActivate()? ​

ts
optional onActivate(instance: object, container: Container): void;

Defined in: src/wirestate-core/plugin/plugin.ts:89

Runs after a service instance is activated, before its @OnActivation.

Parameters ​

ParameterTypeDescription
instanceobjectThe activated instance.
containerContainerContainer that activated it.

Returns ​

void


onContainerDeprovision()? ​

ts
optional onContainerDeprovision(container: Container): void;

Defined in: src/wirestate-core/plugin/plugin.ts:81

Runs once at the end of a container deprovision cycle, after all teardown.

Parameters ​

ParameterTypeDescription
containerContainerContainer being deprovisioned.

Returns ​

void


onContainerProvision()? ​

ts
optional onContainerProvision(container: Container): void;

Defined in: src/wirestate-core/plugin/plugin.ts:74

Runs once at the start of a container provision cycle, before instance wiring.

Parameters ​

ParameterTypeDescription
containerContainerContainer being provisioned.

Returns ​

void


onDeactivate()? ​

ts
optional onDeactivate(instance: object, container: Container): void;

Defined in: src/wirestate-core/plugin/plugin.ts:97

Runs as a service instance is deactivated, after its @OnDeactivation.

Parameters ​

ParameterTypeDescription
instanceobjectThe instance being deactivated.
containerContainerContainer that owns it.

Returns ​

void


onDeprovision()? ​

ts
optional onDeprovision(instance: object, container: Container): void;

Defined in: src/wirestate-core/plugin/plugin.ts:118

Runs as a provisioned instance is deprovisioned, after its @OnDeprovision.

Parameters ​

ParameterTypeDescription
instanceobjectThe instance being deprovisioned.
containerContainerContainer that owns it.

Returns ​

void


onProvision()? ​

ts
optional onProvision(
   instance: object, 
   container: Container, 
   addDisposer: (dispose: () => void) => void): void;

Defined in: src/wirestate-core/plugin/plugin.ts:110

Wires a provisioned instance, before any user @OnProvision.

Parameters ​

ParameterTypeDescription
instanceobjectThe provisioned instance.
containerContainerContainer being provisioned.
addDisposer(dispose: () => void) => voidRegisters a teardown callback for this provision cycle.

Returns ​

void

Remarks ​

Register teardown with addDisposer. Disposers run (reverse order, failsafe) at deprovision. A throw here unwinds the whole provision cycle.


participates()? ​

ts
optional participates(token: ServiceToken): boolean;

Defined in: src/wirestate-core/plugin/plugin.ts:67

Declares whether a binding token is a participant this plugin wires.

Parameters ​

ParameterTypeDescription
tokenServiceTokenBinding token to inspect.

Returns ​

boolean

Whether the plugin participates in this token.

Remarks ​

Token/class-level so it can drive force-activation: a token this returns true for is resolved (activated) at provision even if nothing injected it, and the instance is then delivered to WirestatePlugin.onProvision. Omit for a pure observer that force-activates nothing.