initialize method

bool initialize({
  1. Map? entries,
  2. Map<Type, InitFactory>? factories,
  3. Future initAsync()?,
})

Initializes the factory with a set of entries, factories, and an optional async setup task.

This method is called by Control.initControl and should generally not be called directly unless you are managing your own ControlFactory instance.

  • entries: A map of singleton objects to be added to the factory's store.
  • factories: A map of InitFactory functions for lazy object creation.
  • initAsync: An asynchronous function to execute as the final step of initialization.

Returns true if initialization was successful, or false if the factory was already initialized.

Implementation

bool initialize(
    {Map? entries,
    Map<Type, InitFactory>? factories,
    Future Function()? initAsync}) {
  if (_initialized) {
    return false;
  }

  _initialized = true;

  _items[ControlFactory] = this;
  _items[ControlBroadcast] = _broadcast;

  if (entries != null) {
    _items.addAll(entries);
  }

  if (factories != null) {
    _factory.addAll(factories);
  }

  _items.forEach((key, value) {
    if (value is Initializable) {
      _init(value, args: {});

      printDebug('Factory init $key - ${value.runtimeType.toString()}');
    }

    if (value is DisposeHandler) {
      value.preferSoftDispose = true;

      printDebug(
          'Factory prefers soft dispose of $key - ${value.runtimeType.toString()}');
    }
  });

  _initializeAsync(initAsync);

  return true;
}