lazySingleton<T> method

void lazySingleton<T>(
  1. T factory(
    1. Container
    ), {
  2. String? name,
})

Registers a factory that will be executed once and its result stored as a singleton.

Implementation

void lazySingleton<T>(T Function(Container) factory, {String? name}) {
  _factories[_key<T>(name)] = (c) {
    final res = factory(c);
    _singletons[_key<T>(name)] = res;
    return res;
  };
}