Skip to content

Function: provideContainer() ​

ts
function provideContainer<E>(options: ContainerProviderOptions): ProvideContainerDecorator<E>;

Defined in: src/wirestate-lit/container/provide-container.ts:94

Decorator that provides an IoC container to child components.

Type Parameters ​

Type Parameter
E extends ReactiveElement

Parameters ​

ParameterTypeDescription
optionsContainerProviderOptionsProvisioning options.

Returns ​

ProvideContainerDecorator<E>

An instance of ProvideContainerDecorator.

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
import { EventsPlugin } from "@wirestate/core";
import { ContainerProvider, provideContainer } from "@wirestate/lit";
import { LitElement } from "lit";

class MyRootElement extends LitElement {
  @provideContainer({
    config: {
      bindings: [LoggerService],
      plugins: [new EventsPlugin()],
    },
  })
  private containerProvider!: ContainerProvider;
}
typescript
import { Container } from "@wirestate/core";
import { ContainerProvider, provideContainer } from "@wirestate/lit";
import { LitElement } from "lit";

const container = new Container({ bindings: [LoggerService] });

class MyRootElement extends LitElement {
  @provideContainer({ container })
  private containerProvider!: ContainerProvider;
}