bindWhen<T> method

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

Binds an implementation to an interface when requested within a specific context.

Allows different implementations of the same interface to be used in different contexts. The context is specified during resolution.

T - The abstract type to bind context - The context identifier for this binding factory - Factory function that creates the instance singleton - Whether to cache and reuse the instance

Implementation

@override
void bindWhen<T>(
  String context,
  dynamic Function(ContainerInterface) factory, {
  bool singleton = false,
}) {
  _contextualBindings[context] ??= {};
  _contextualBindings[context]![T] = _Binding(factory, singleton: singleton);
}