put<T> static method

T put<T>(
  1. T dependency, {
  2. String? tag,
})

Registers a singleton instance in the dependency store.

If a dependency with the same type and tag already exists, it will be overwritten with a warning logged.

Parameters:

  • dependency: The instance to register
  • tag: Optional identifier for multiple instances of the same type

Returns the registered instance.

Example:

final controller = Dependency.put(MyController());

// With tag
Dependency.put(AuthService(), tag: 'primary');

Implementation

static T put<T>(
  T dependency, {
  String? tag,
}) {
  final key = _getKey(dependency.runtimeType, tag: tag);

  if (_dependencyStore[key] != null) {
    Logger.warn(
      'Dependency of type ${dependency.runtimeType} is being overwritten',
      tag: 'Dependency',
    );
  }

  _dependencyStore[key] = dependency;

  // // Note: fenix mode for put() is currently not fully implemented
  // // For phoenix behavior with recreation, use lazyPut() instead
  // if (fenix) {
  //   // Reserved for future implementation
  // }

  return _dependencyStore[key];
}