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
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, 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
| Parameter | Type | Description |
|---|---|---|
container | Container | Container the plugin is registered on. |
addRollback | (rollback: () => void) => void | Registers 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()?
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
| 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:81
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:74
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:97
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:118
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:110
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:67
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.