B
B
BonBon Slick2020-12-26 18:39:26
symfony
BonBon Slick, 2020-12-26 18:39:26

Is the handler of domain event considered a CQRS pattern handler?

CQRS we have command / query, but what about events?
For a team or a Queri, we have a user case, but is an event considered a user case because it lies and belongs to another layer altogether, Domain? While CQRS is Application.

So, conditionally, I make a handler that listens to the UserRegistered Domain event, where should I put this handler? All handlers are the Infrastructure ES layer, but at the same time it is the handler of the conditional command. After all, the differences between the team and the event are minimal. They carry a minimum of data, they talk about events. The command that should happen, the event that has already happened, both will dispatch the event bass only different interfaces and middleware.

Now the structure is

Application -> CQRS -> Command / Query -> UseCase / Handler -> RegisterUser / RegsterUserHandler
Domain -> Entity -> Event -> UserRegisteredEvent
Infrastructure -> EventSourcing -> Bus -> Handlers -> UserRegisteredEventHandler / EmailVerifiedEventHandler ...


Symphony tag is important because we have both EventDispatcher and EventBus, i.e. 2 folders

Infrastructure -> EventSourcing -> EventDispatcher -> Listeners -> UserRegisteredListener
Infrastructure -> EventSourcing -> EventDispatcher -> Subscribers -> UserRegisteredSubscriber

So there is an additional semantic load for symphony composers and conductors. After all, EventDispatcher, in my opinion, is suitable exclusively and only for using DomainEntityEvent, the difference from DomainEvent is that UserRegistered is an event of the entire domain, and UserPasswordUpdated is an Entity. In the first one, asynchrony is needed, and in the second, sequence and synchronism are needed to save the event in the database. If you have other thoughts about Bus vs EventDispatcher, here's a question for which one and ...

In general, what is your opinion, where to put the Domain event handler that was dispatched through the bus event, like commands / queries?
Why do you think so?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2020-12-27
@BonBonSlick

one.

For a team or Queri, we have a user case, but is an event considered a user case because it lies and belongs to another layer altogether, Domain? While CQRS is Application.
Event cannot be Use Case. Event is what happened and Use Case is what needs to be done (use cases).
2. So, conditionally, I make a handler that listens to the UserRegistered Domain event, where should I put this handler? Over here .
All handlers are the Infrastructure ES layer, but at the same time it is the handler of the conditional command.
Not a correct statement. Infrastructure is what comes from the framework. Take the Slim Framework and you will understand how empty it is). Everything else can be abstracted into their own classes.
3. You can also see the structure at the link above.
Application
    Command
    Query

Domain
    Entity
        class Id
        interface UserRepository
    Service
        interface PasswordHasher
    interface Flusher

Infrastructure
    Entity
        class IdType
        class DoctrineUserRepository implements UserRepository
    Service
        class CryptPasswordHasher implements PasswordHasher
    class DoctrineFlusher implements Flusher

In my projects, I omit these 4 folders and do everything without Application, Domain, etc. If you have no problems understanding what is what, you can omit it. Such horizontal foldering is often redundant. Example
4
Symphony tag is important because we have both EventDispatcher and EventBus, i.e. 2 folders
When you start designing for DDD, the Framework is usually omitted. The bare minimum is used, and everything else is isolated. At the same time, you are not prohibited from using symphony components or other framework-independent components. But if it's a bundle, you won't go far)
5.
In general, what is your opinion, where to put the Domain event handler that was dispatched through the bus event like commands / queries?
See Clause 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question