It can often be useful to determine if you are running in a Scope.
You can detect if your code is running within a Scope by calling:
// or
You can also detect if a specific ScopeKey exists by calling:
if (hasScopeKey(ageKey))
// change my behaviour
/// or
if (Scope.hasScopeKey(ageKey))
// change my behaviour
Both forms of isWithinScope and hasScopeKey are identical and are provided for consistency with the two forms of the use method.
Detecting if you are within a Scope is really useful for unit testing.
Your unit tests can inject a ScopeKey and change your code can then change its behaviour when running within a unit test.
This can be easier then setting up a full mock framework.
Last modified 8mo ago
Copy link