put<T> static method

T put<T>(
  1. T dependency, {
  2. String? tag,
  3. bool fenix = false,
})

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
  • fenix: If true, the dependency will auto-recreate after deletion

Returns the registered instance.

Example:

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

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

// Phoenix mode - auto-recreates
Dependency.put(CacheService(), fenix: true);

Implementation

static T put<T>(
  T dependency, {
  String? tag,
  bool fenix = false,
}) {
  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;

  if (fenix) {
    _lazyBuilders[key] = () => dependency;
  }

  return _dependencyStore[key];
}