Comments (4)
Which is your use case?
When we have to split operations between different Bounded Contexts or Modules, we inject the Command or Query Bus in the Application Service (not the Command Handler). This way, we still encapsulate all the use case in the very same Application Service.
Example: Check if a Course
exists before creating a Video
referring to it. In this case we will inject the QueryBus
in the VideoCreator
service, making a FindCourseQuery
and checking if the response is not null before actually creating the Video
aggregate, saving it to the repository, and publishing the corresponding domain event.
This way, we would be encapsulating the whole use case as previously said, making it reusable without taking into account the entry point (we could be executing that very same use case based on a domain event, and we would still want to match all the preconditions without having to implement them also in the domain event subscriber).
If that makes sense to you, could you try injecting the Command/Query Bus into the actual Application Service to be executed and see if that works?
Thanks for the report!
from php-ddd-example.
Just a clarification, we don't inject the command bus
in the application services or in another command handler, only in the controllers.
Why? Because our services only do 1 thing. If we need to do more, instead of publishing a command
, we publish a domain event
.
So, instead of doing something like:
UserPostController
publishRegisterUserCommand
- Is handled by its command handler and calls the Application Service
- This application service register the user (insert in DB)
- Then publish another command for Send a Welcome Email to the User
- Then publish another command for giving the user a Welcome Bonus
- And more and more commands every time we need to do anything when a user is registered
With this approach, we're violating the OCP principle given every time we need to extend our code we're modifying the Application Service.
We do something more like:
UserPostController
publishRegisterUserCommand
- Is handled by its command handler and calls the Application Service
- This application service register the user
- Then publish a
UserRegistered
domain event - Then another uses cases, atomically, can react to it (after being handled by a
Subscriber
)
With this approach we're respecting the OCP and also we have a reactive, more scalable and reliable system.
With this in mind, if you want to have services with the command handler injected (again, a thing that we don't recommend :P) and you want to avoid having that cyclic dependency, you need to do lazy all the application services.
from php-ddd-example.
Thanks you very much for your complete response, finally i changed my way of doing, i created a console command (controller purpose), that dispatch a command to a handler. This handler then indirectly update the model of a different bounded context via domain Events. Like you explain i think.
from php-ddd-example.
ππππ
Peeerfect!! π
Have fun!!!
from php-ddd-example.
Related Issues (20)
- Error on make build HOT 5
- Modelos de Dominio con name creators
- Application services expose entities
- The flush method should be outside repositories
- We should not flush an entity
- Unable to create the "cache" directory HOT 3
- Finder application services has different behaviours. Why?
- Windows users HOT 1
- On make build in windows "installed make using choco" HOT 1
- Errror make build new version symfony HOT 2
- Elasticsearch + criteria pattern
- Autenticar usuario implementa Command en lugar de Query
- Database transaction boundary HOT 2
- json_encode() y json_decode() puede lanzar exception desde PHP 7.3
- Deptrac support HOT 1
- Incongruencias entre readme y makefile
- [CONSULTA] Relacion Video y Course
- ΒΏPor quΓ© `CourseRenamer` instancia el Servicio de AplicaciΓ³n `CourseFinder` en lugar de un Servicio de Dominio?
- Problema al ejecutar el `make build` HOT 1
- What buisness logic does Utils.php provides?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-ddd-example.