@djodjonx/wiredi
    Preparing search index...

    Function useBuilder

    • A composable function for setting up and interacting with a dependency injection container based on a BuilderConfig. It ensures that dependencies are registered only once per builderId and provides a type-safe resolve method.

      The resolve method is strictly type-checked to only allow tokens defined within the injections array of the provided config.

      ⚠️ Requires useContainerProvider() to be called first at app entry point.

      Type Parameters

      • C = null

        The type of the context object that might be passed to value providers.

      • Tokens extends readonly any[] = []

        The inferred tuple of allowed tokens from the config.

      Parameters

      • config: TypedBuilderConfig<C, Tokens>

        The typed builder configuration object.

      • Optionalcontext: C

        An optional context object that can be passed to value providers in the injections.

      Returns IUseBuilder<Tokens[number]>

      An IUseBuilder instance with a type-safe resolve method.

      // main.ts - Entry point
      import { useContainerProvider, TsyringeProvider } from '@djodjonx/wiredi'
      useContainerProvider(new TsyringeProvider())

      // anywhere.ts
      import { useBuilder } from '@djodjonx/wiredi'
      const { resolve } = useBuilder(myConfig)
      const service = resolve(MyService)