putFactory<T> method

void putFactory<T>(
  1. T factory(), {
  2. String? tag,
})

Register a factory that creates new instances each time

Implementation

void putFactory<T>(T Function() factory, {String? tag}) {
  if (_disposed) {
    throw Exception('Cannot register factory in a disposed scope: $name');
  }

  final key = _makeKey<T>(tag);
  final trackingKey = _getDependencyKey(T, tag);

  // Store the factory
  _factories[key] = factory;

  // Mark as a factory in the use count tracking (-2 = factory)
  _useCount[trackingKey] = -2;

  if (ZenConfig.enableDebugLogs) {
    ZenLogger.logDebug(
        'Registered factory for $T${tag != null ? ' with tag $tag' : ''}');
  }
}