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 (@OnActivated / @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 plugin shadows a handled kind.
Example
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()?
optional install(container: Container): void;Defined in: src/wirestate-core/plugin/plugin.ts:48
Contributes bindings (or other one-time setup) when the plugin is registered.
Parameters
| Parameter | Type | Description |
|---|---|---|
container | Container | Container the plugin is registered on. |
Returns
void
Remarks
Runs once, on the container the plugin is registered on (not on inheriting children), before any binding activates.
onActivate()?
optional onActivate(instance: object, container: Container): void;Defined in: src/wirestate-core/plugin/plugin.ts:95
Runs after a service instance is activated, before its @OnActivated.
Parameters
| Parameter | Type | Description |
|---|---|---|
instance | object | The activated instance. |
container | Container | Container that activated it. |
Returns
void
onContainerDeprovision()?
optional onContainerDeprovision(container: Container): void;Defined in: src/wirestate-core/plugin/plugin.ts:87
Runs once at the end of a container deprovision cycle, after all teardown.
Parameters
| Parameter | Type | Description |
|---|---|---|
container | Container | Container being deprovisioned. |
Returns
void
onContainerProvision()?
optional onContainerProvision(container: Container): void;Defined in: src/wirestate-core/plugin/plugin.ts:80
Runs once at the start of a container provision cycle, before instance wiring.
Parameters
| Parameter | Type | Description |
|---|---|---|
container | Container | Container being provisioned. |
Returns
void
onDeactivate()?
optional onDeactivate(instance: object, container: Container): void;Defined in: src/wirestate-core/plugin/plugin.ts:103
Runs as a service instance is deactivated, after its @OnDeactivation.
Parameters
| Parameter | Type | Description |
|---|---|---|
instance | object | The instance being deactivated. |
container | Container | Container that owns it. |
Returns
void
onDeprovision()?
optional onDeprovision(instance: object, container: Container): void;Defined in: src/wirestate-core/plugin/plugin.ts:124
Runs as a provisioned instance is deprovisioned, after its @OnDeprovision.
Parameters
| Parameter | Type | Description |
|---|---|---|
instance | object | The instance being deprovisioned. |
container | Container | Container that owns it. |
Returns
void
onProvision()?
optional onProvision(
instance: object,
container: Container,
addDisposer: (dispose: () => void) => void): void;Defined in: src/wirestate-core/plugin/plugin.ts:116
Wires a provisioned instance, before any user @OnProvision.
Parameters
| Parameter | Type | Description |
|---|---|---|
instance | object | The provisioned instance. |
container | Container | Container being provisioned. |
addDisposer | (dispose: () => void) => void | Registers 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()?
optional participates(token: ServiceToken): boolean;Defined in: src/wirestate-core/plugin/plugin.ts:62
Declares whether a binding token is a participant this plugin wires.
Parameters
| Parameter | Type | Description |
|---|---|---|
token | ServiceToken | Binding 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.
Properties
handles?
readonly optional handles?: readonly symbol[];Defined in: src/wirestate-core/plugin/plugin.ts:73
Messaging-handler kinds this plugin owns (advanced).
Remarks
Used by the built-in messaging plugins. Provision matches declared handler metadata against the union of registered plugins' kinds and throws on a kind no plugin handles. A nearer plugin owning a kind shadows an ancestor's of the same kind. Observer plugins usually omit this field.