Skip to content

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

ParameterTypeDescription
optionsContainerProviderOptionsProvisioning options.

Returns

ContainerProviderDecorator<E>

An instance of ContainerProviderDecorator.

Remarks

The container is provided via Lit context.

  • Pass container to expose an external container without taking ownership.
  • Pass config to 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;
}