Comments (4)
From my understanding, commands should have no knowledge of each other? -- I may be wrong?
I think you are doing it the best way, especially as certain events may need to dispatch a case specific command.
from tactician.
@alexbilbie Good question, it's come up a couple times. I should probably add it to the docs or blog...
Short answer: I'm guessing the stack trace is probably happening because of the InMemoryLocator having a concrete instance, so circular reference. You could work around it by creating a lazy-loading locator based on your DI container.
That aside though, I'd recommend one of these two approaches:
- Don't reuse the Commands directly. Instead, find out what the common factor is between them (some action or service or object), extract that and reuse it between your handlers. I know it's a boring old OOP answer but there's a good chance you'll find some separate object in there that you can test and maintain better this way.
- On a broader scale, if you're doing this because the two commands aren't closely related or you're trying to keep them decoupled, I would recommend doing something similar to what you're already doing: listen for a domain event, treat the listener as a thin controller that just fires off another Command there.
For the second solution, I would definitely use a domain event here, btw, not a CommandReceived or CommandExecuted type event, but something properly driven by your model. That makes it a little less brittle if your domain event is something that might shift locations or be used in multiple places in the future: if you've got two or three ways to do something with your model, just always raise the same event and the rest of the app will react accordingly.
For a small use case, this event setup might feel like boilerplate but it really helps decouple the different parts of the application. If it's very close by in the application though, I would take the first approach of just extracting a reusable object, rather than firing another command.
from tactician.
I will stick with my current approach, the commands in question are highly disparate in function but in certain cases they need to be fired as a result of the other.
Thank you!
from tactician.
More than welcome, I would definitely consider using domain events rather than events raised in the handler for this, but it'll be okay either way. Thanks for asking!
from tactician.
Related Issues (20)
- [RFC] Chained Inflector HOT 4
- [DOC] Missing parameter HOT 3
- We created queue interop based middleware for tactician. HOT 1
- Testing with no interface HOT 2
- LICENSE file missing for re-distribution HOT 1
- V2: InMemoryLocator replacement? HOT 2
- Delete the 2.0 branch HOT 1
- Implement CommandBus against interface HOT 4
- Broken Examples HOT 8
- PHP8 Support HOT 1
- Release v2 HOT 14
- RFC: Add markdown linting for `gh_pages` HOT 1
- Make Middleware::execute internal HOT 6
- Locking middleware does not work with exceptions HOT 9
- PHP version constraint tigher than required HOT 5
- Plugin to prioritize command HOT 3
- Scheduling commands HOT 2
- Yii adapter for Tactician HOT 2
- 1.0 release ? HOT 2
- Tests missing in releases HOT 3
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 tactician.