registerSingleton<T> method
Registers a singleton. Any attempt to resolve the
type within this container will return object
.
Returns object
.
Implementation
T registerSingleton<T>(T object, {Type? as}) {
as ??= T == dynamic ? as : T;
if (_singletons.containsKey(as ?? object.runtimeType)) {
throw StateError('This container already has a singleton for ${as ?? object.runtimeType}.');
}
_singletons[as ?? object.runtimeType] = object;
return object;
}