ecotoneframework / ecotone-dev

Ecotone Framework Development - This is Monorepo which contains all official public modules
https://docs.ecotone.tech
Other
37 stars 16 forks source link

How to use #[QueryHandler] #379

Closed galliroberto closed 1 month ago

galliroberto commented 1 month ago

Ecotone version(s) affected: 1.231.0 Symfony version: 6.4.11

Description
I want to send query FindCompanyCollectionQuery throw queryBus and use queryHandler to handle it.

I get the error

Can't send query to Organization\\Modules\\Company\\Domain\\Query\\FindCompanyCollectionQuery. No Query Handler defined for it. Have you forgot to add #[QueryHandler] to method?

I also tried with sendWithRouting

I get the error:

Can't send query to customRoute. No Query Handler defined for it. Have you forgot to add #[QueryHandler] to method?

I also tried with commandBus and #[CommandHandler] and get the error that route is not defined.

Context
image

image

jlabedo commented 1 month ago

Hello @galliroberto , I think it is because of a misconfiguration. I supposed from your screenshots that you are using Ecotone with Symfony, and that your source code is under an "Organization" namespace (not the default "App" namespace).

By default, Ecotone looks for attributes in the "App" namespace and the "src" directory. If you have a different setup, you should add the namespaces configuration in Symfony (see: https://docs.ecotone.tech/modules/symfony/symfony-ddd-cqrs-event-sourcing#namespaces)

Something like this in config/packages/ecotone.yaml:

ecotone: 
    namespaces: ["Organization"]
galliroberto commented 1 month ago

Thank you so much. You are really helpful