registerSingle<T> method

void registerSingle<T>(
  1. T construct(), {
  2. bool lazy = true,
})

Registers a new construct function for type T that will be called once to create the object of the specified type.

Optionally a lazy parameter can be specified to control the creation of this singleton object. Setting the parameter to false, will cause the construct to be called immediately. Defaults to true.

Implementation

void registerSingle<T>(T Function() construct, {bool lazy = true}) {
  _tryRegister<T>(() {
    if (!lazy) _instances[T] = construct();
    return _IocDef(construct, lazy: lazy, single: true);
  });
}