lazySingleton<T extends Object?> method

bool lazySingleton<T extends Object?>(
  1. InstanceBuilder<T> builder, {
  2. String? id,
})

Register a builder function for creating a new instance of T with an id optional as InstanceManageMode.singleton.

Returns true when instance has been registered.

It's a ways to manage a instance, which registers a builder function and creates the instance only once.

This mode preserves the instance and its states, even if the dependency tree stops using it.

Use Reactter.destroy if you want to force destroy the instance and its register.

It consumes less CPU than builder and factory, but uses more RAM than the other modes.

This method is equivalent to calling:

Reactter.register<T>(
  builder,
  id: id,
  mode: InstanceManageMode.singleton,
);

Implementation

bool lazySingleton<T extends Object?>(
  InstanceBuilder<T> builder, {
  String? id,
}) {
  return register<T>(
    builder,
    id: id,
    mode: InstanceManageMode.singleton,
  );
}