registerFactory<T, R extends T> method

void registerFactory<T, R extends T>(
  1. SpotGetter<R> locator, {
  2. String? name,
})

Register a factory that creates a new instance on each resolution.

This registration only applies to this container and its children.

Type Parameters:

  • T: The interface or base type to register
  • R: The concrete implementation (must extend or implement T)

Parameters:

  • locator: Factory function that creates instances
  • name: Optional name qualifier for named instances

Implementation

void registerFactory<T, R extends T>(SpotGetter<R> locator, {String? name}) {
  final key = SpotKey<T>(T, name);

  if (registry.containsKey(key) && logging) {
    log.w('Overriding factory in scope: $key with $R');
  }

  registry[key] = SpotService<T>(SpotType.factory, locator as SpotGetter<T>, R);

  if (logging) log.v('Registered factory in scope: $key -> $R');
}