scope
  • Overview
  • Fundamentals
    • Installing
    • Scope
      • Creating
      • Using
      • Detecting
      • Nesting
      • Async
      • Single and Sequence factories
      • Returning values
      • Mutable values
    • GlobalScope
    • Overriding
    • Type safety
    • Debugging
    • How Scope Works
  • Guides
    • Best Practice
    • How is Scope different from 'x'
Powered by GitBook
On this page
  1. Fundamentals
  2. Scope

Detecting

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:

Scope.isWithinScope();

// or

isWithinScope();

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.

PreviousUsingNextNesting

Last updated 3 years ago