wire method

  1. @override
void wire()
override

Implementation

@override
void wire() {
  int numberOfServices;
  do {
    numberOfServices = _factories.length;

    // ignore: omit_local_variable_types
    List<Type> factoriesToRemove = [];

    _factories.forEach((Type t, _ServiceWithDependencies s) {
      var allDepsAvailable = s.dependencies.where((t) => !_has(t)).isEmpty;
      if (allDepsAvailable) {
        var dependencies = s.dependencies.map((t) {
          var dep = _get(t);
          return dep is InjectionToken ? dep.value : dep;
        }).toList();
        var service = s.serviceFactory(dependencies);
        _register(t, service);
        factoriesToRemove.add(t);
      }
    });
    factoriesToRemove.forEach((Type t) => _factories.remove(t));
  } while (numberOfServices > _factories.length);

  if (_factories.isNotEmpty) {
    throw _buildAutoWireException();
  }
}