# Nesting

Scopes can be nested with the same keys or different keys injected at each level.

When you inject a key/value pair into a nested Scoped and then call `use,` the value from the closest Scope with a matching key is used.

If the key isn't in the immediate Scope we search up through parent scopes.

```dart
import 'package:scope/scope.dart';
void main() {

  // parent scope
  Scope()
    ..value<String>(greetingKey, 'Hello')
    ..value<int>(emphasisKey,  1)
     ..run(() {
    
          /// Nest child Scope (1)
          Scope()
          ..value<String>(greetingKey, 'Good day')
          ..run(() {
               Greeter().greet('Philipp'); // 'Good day, Philipp!'
          });

         /// Sibling of (1) = also nested witin the parent scope
         Scope()
          ..value<int>(emphasisKey, 3)
          ..run(() {
               Greeter().greet('Paul'); // 'Hello, Paul!!!'
         });
  });
}
```

There is no limit to the level of nesting that can be used.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://scope.onepub.dev/fundamentals/scope/nesting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
