registerAsync<T, R extends T> method

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

Register an async singleton with asynchronous initialization.

The async singleton is scoped to this container.

Type Parameters:

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

Parameters:

  • locator: Async factory function called once to create the singleton
  • name: Optional name qualifier for named instances

Implementation

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

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

  registry[key] = SpotService<T>(
    SpotType.asyncSingleton,
    null,
    R,
    asyncLocator: locator as SpotAsyncGetter<T>,
  );

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