bindWhen<T> abstract method

void bindWhen<T>(
  1. String context,
  2. dynamic factory(
    1. ContainerInterface
    ), {
  3. bool singleton = false,
})

Registers a contextual binding for type T under a specific context.

This allows different factories for T based on the context provided during resolution. If singleton is true, the instance is created once per context and reused.

  • context: A string key identifying the context.
  • factory: A function that takes the container and returns an instance of T.
  • singleton: If true, the factory is treated as a singleton within the context.

Throws an exception if a binding for T under the same context already exists.

Implementation

void bindWhen<T>(
  String context,
  dynamic Function(ContainerInterface) factory, {
  bool singleton = false,
});