Function: containerProvide()
ts
function containerProvide<E>(options: ContainerProviderOptions): ContainerProviderDecorator<E>;Defined in: src/wirestate-lit/provision/container-provide.ts:72
Decorator that provides an IoC container to child components.
Type Parameters
| Type Parameter |
|---|
E extends ReactiveElement |
Parameters
| Parameter | Type | Description |
|---|---|---|
options | ContainerProviderOptions | Provisioning options. |
Returns
An instance of ContainerProviderDecorator.
Remarks
The container is provided via Lit context.
- Pass
containerto expose an external container without taking ownership. - Pass
configto create a managed container when the host connects, run provider lifecycle hooks while connected, destroy it on disconnect, and recreate it on reconnect.
The container value is published through Lit context only while the host is connected. Before the first connection and after disconnection, the provider value is undefined.
Examples
typescript
class MyRootElement extends LitElement {
@containerProvide({
config: {
seed: { someData: "value" },
entries: [LoggerService],
},
})
private containerProvider!: ContainerProvider;
}typescript
class MyRootElement extends LitElement {
@containerProvide({ container: container })
private containerProvider!: ContainerProvider;
}