putOrFind<S> method

S putOrFind<S>(
  1. S builder(), {
  2. String? tag,
  3. bool permanent = false,
})

Resolves the dependency, or registers it via builder if not found.

Implementation

S putOrFind<S>(S Function() builder, {String? tag, bool permanent = false}) {
  final scope = _ScopeProvider.of(_context);
  if (scope != null) {
    final instance = scope.findOrNull<S>(tag: tag);
    if (instance != null) return instance;
    return scope.put<S>(builder, tag: tag, permanent: permanent);
  }

  final instance = Levit.findOrNull<S>(tag: tag);
  if (instance != null) return instance;
  return Levit.put<S>(builder, tag: tag, permanent: permanent);
}