Provides meaningful exception messages.
        /// <summary>
        /// Gets a named scope from the request.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="scopeParameterName">Name of the scope parameter.</param>
        /// <returns>The scope.</returns>
        /// <exception cref="ScopeDisposedException">Thrown when the scope is already disposed.</exception>
        /// <exception cref="UnknownScopeException">Throw if no scope with the specified name exists in the current context.</exception>
        public static object GetNamedScope(this IContext context, string scopeParameterName)
        {
            object scope = context.TryGetNamedScope(scopeParameterName);

            if (scope == null)
            {
                throw new UnknownScopeException(ExceptionFormatter.CouldNotFindScope(context.Request, scopeParameterName));
            }

            return(scope);
        }
        /// <summary>
        /// Gets a named scope from the request.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="scopeParameterName">Name of the scope parameter.</param>
        /// <returns>The scope.</returns>
        /// <exception cref="ScopeDisposedException">Thrown when the scope is already disposed.</exception>
        /// <exception cref="UnknownScopeException">Throw if no scope with the specified name exists in the current context.</exception>
        public static object GetScope(IContext context, string scopeParameterName)
        {
            NamedScopeParameter namedScopeParameter = GetNamedScopeParameter(context, scopeParameterName);

            if (namedScopeParameter != null)
            {
                if (namedScopeParameter.Scope.IsDisposed)
                {
                    throw new ScopeDisposedException();
                }

                return(namedScopeParameter.Scope);
            }

            if (context.Request.ParentContext != null)
            {
                return(GetScope(context.Request.ParentContext, scopeParameterName));
            }

            throw new UnknownScopeException(ExceptionFormatter.CouldNotFindScope(context.Request, scopeParameterName));
        }