コード例 #1
0
    def _register_crud_event_listener(self, event: ff.TypeOfEvent,
                                      command: str, context: ff.Context):
        class DoInvokeOn(ff.InvokeOn):
            pass

        self._event_resolving_middleware.add_event_listener(
            self._container.build(DoInvokeOn, command_name=command), event)
        if DoInvokeOn not in context.event_listeners:
            context.event_listeners[DoInvokeOn] = []
        context.event_listeners[DoInvokeOn].append(event)
コード例 #2
0
    def _create_query_handler(self, entity: Type[Entity], context: ff.Context):
        query_name = inflection.pluralize(entity.__name__)

        class Query(ff.QueryService[entity]):
            pass

        Query.__name__ = query_name
        fqn = f'{context.name}.{query_name}'

        self._query_resolving_middleware.add_query_handler(
            self._container.build(Query), fqn)
        context.query_handlers[Query] = fqn
コード例 #3
0
    def _create_crud_command_handler(self, context: ff.Context, entity,
                                     name_prefix):
        name = f'{name_prefix}Entity'
        base = getattr(ff, name)

        class Action(base[entity]):
            pass

        name = f'{name_prefix}{entity.__name__}'
        fqn = f'{context.name}.{name}'
        if not self._command_resolving_middleware.has_command_handler(fqn):
            Action.__name__ = name
            self._command_resolving_middleware.add_command_handler(
                self._container.build(Action), fqn)
            context.command_handlers[Action] = fqn
コード例 #4
0
    def _create_invoke_command_handler(self, entity: Type[Entity],
                                       context: ff.Context, method_name: str):
        command_name = f'{entity.__name__}::{inflection.camelize(method_name)}'

        class Invoke(InvokeCommand[entity]):
            pass

        Invoke.__name__ = f'Invoke{command_name}'
        fqn = f'{context.name}.{command_name}'

        self._command_resolving_middleware.add_command_handler(
            self._container.build(Invoke, method=method_name), fqn)
        context.command_handlers[Invoke] = fqn

        return fqn