factory<T extends Object?> method

T? factory<T extends Object?>(
  1. InstanceBuilder<T> builder, {
  2. String? id,
  3. Object? ref,
})
inherited

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.

Under the following conditions:

  • if not found and hasn't registered it, registers, creates and returns it.
  • if not found and has registered it, creates and returns it.
  • if found it, returns it.
  • else return null.

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.create<T>(
  builder,
  id: id,
  ref: ref,
  mode: DependencyMode.factory,
);

Implementation

T? factory<T extends Object?>(
  InstanceBuilder<T> builder, {
  String? id,
  Object? ref,
}) {
  return create<T>(
    builder,
    id: id,
    ref: ref,
    mode: DependencyMode.factory,
  );
}