public function callMiddleware($id, $owner)
    {
        if ($owner->freezed) {
            return $owner;
        }

        $class = get_class($owner);
        foreach ($owner->middleware as $definition) {
            $middleware = make($definition);
            if (!$middleware instanceof MiddlewareContract) {
                throw new InvalidConfigException(sprintf("'%s' is not a valid middleware", get_class($middleware)));
            }

            $result = $middleware->handle($owner);
            if ($result === false) {
                break;
            } elseif ($result instanceof $class) {
                $owner = $result;
            } elseif ($result !== null) {
                throw new InvalidValueException(sprintf(
                    'The return value of %s::handle() should be one of false, null and %s',
                    get_class($middleware), $class
                ));
            }
        }

        $this->bind($id, $owner, true);
        $owner->freeze();

        return $owner;
    }