lazyFactory<T extends Object?> method

bool lazyFactory<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.factory.

Returns true when instance has been registered.

It's a ways to manage an instance, which registers a builder function only once and creates the instance if not already done.

When the dependency tree no longer needs it, the instance is deleted and the builder function is kept in the register.

It uses more RAM than builder but not more than singleton, and consumes more CPU than singleton but not more than builder.

This method is equivalent to calling:

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

Implementation

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