def depsignal(class_, signal_name, *, defer=False):
    """
    Connect the decorated method or coroutine method to the addressed signal on
    a class on which the service depends.

    :param class_: A service class which is listed in the
                   :attr:`~.Meta.ORDER_AFTER` relationship.
    :type class_: :class:`Service` class or one of the special cases below
    :param signal_name: Attribute name of the signal to connect to
    :type signal_name: :class:`str`
    :param defer: Flag indicating whether deferred execution of the decorated
                  method is desired; see below for details.
    :type defer: :class:`bool`

    The signal is discovered by accessing the attribute with the name
    `signal_name` on the given `class_`. In addition, the following arguments
    are supported for `class_`:

    1. :class:`aioxmpp.stream.StanzaStream`: the corresponding signal of the
       stream of the client running the service is used.

    2. :class:`aioxmpp.Client`: the corresponding signal of the client running
       the service is used.

    If the signal is a :class:`.callbacks.Signal` and `defer` is false, the
    decorated object is connected using the default
    :attr:`~.callbacks.AdHocSignal.STRONG` mode.

    If the signal is a :class:`.callbacks.Signal` and `defer` is true and the
    decorated object is a coroutine function, the
    :attr:`~.callbacks.AdHocSignal.SPAWN_WITH_LOOP` mode with the default
    asyncio event loop is used. If the decorated object is not a coroutine
    function, :attr:`~.callbacks.AdHocSignal.ASYNC_WITH_LOOP` is used instead.

    If the signal is a :class:`.callbacks.SyncSignal`, `defer` must be false
    and the decorated object must be a coroutine function.

    .. versionchanged:: 0.9

       Support for :class:`aioxmpp.stream.StanzaStream` and
       :class:`aioxmpp.Client` as `class_` argument was added.
    """

    def decorator(f):
        add_handler_spec(
            f,
            _depsignal_spec(class_, signal_name, f, defer)
        )
        return f
    return decorator