Dispatch an event when the decorated method is called.
    :param event: the event class to instantiate and dispatch.
    :param subject_property: the property name to get the subject.

def dispatch_event(event, subject='id'):
    """
    Dispatch an event when the decorated method is called.
    :param event: the event class to instantiate and dispatch.
    :param subject_property: the property name to get the subject.
    """
    def wrapper(method):
        def inner_wrapper(*args, **kwargs):
            resource = method(*args, **kwargs)
            if isinstance(resource, dict):
                subject_ = resource.get(subject)
                data = resource
            else:
                subject_ = getattr(resource, subject)
                data = resource.__dict__
            event(subject_, data).dispatch()
            return resource
        return inner_wrapper
    return wrapper