findBy method

T? findBy(
  1. String scope,
  2. bool compare(
    1. T
    )
)

Returns first found instance of type in given scope by compare function

Implementation

T? findBy(String scope, bool Function(T) compare) {
  if (!_instances.containsKey(scope)) {
    return null;
  }

  for (final entry in _instances[scope]!.entries) {
    for (final instance in entry.value) {
      if (compare(instance)) {
        return instance;
      }
    }
  }

  return null;
}