-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The sample ResizePicture event is processed twice. #2
Comments
@alexeyzimarev .
|
@paulvanbladel I see the same problem, but if you remove the When call, the Entity can not apply an event and reach a given state without the AggregateRoot. Normally this should be the way to go, but maybe it makes sense to use an Entity on its own in unit tests. Therefore, I would suggest: // Entity.cs
[...]
protected void Apply(object @event)
{
if (_applier == null)
When(@event); // for unit tests
else
_applier(@event); // Applier calls Entity.When
} What do you think? |
@kuechlerm thanks for the reply. Well... not sure... Maybe the author of the book should formulate his exact intension. If a state change is only possible via the AR, not sure then that there can be a backdoor for unit testing. |
You are both right but @paulvanbladel has the point. This is enough:
I don't think that testing entities in isolation make a lot of sense. In the end, entities should not be called otherwise than from the aggregate root. It's the aggregate itself who controls its consistency, not an individual entity. |
@alexeyzimarev a bit reluctant to ask but... everything fine with the missing chapter :) |
@paulvanbladel sorry about the delay. I worked on the code yesterday, introducing some testing patterns and figuring out if I can squeeze the micro-frontends topic to the chapter. It seems like micro-frontends would be a separate thing to publish. I've done the chapter code but it needs more tests. When I confirm it working, I would just need two or three paragraphs of text. |
@alexeyzimarev no worries/sorry Alex. I'm just very thankful you are adding an additional chapter. |
@alexeyzimarev , just one question. At several points through the book you mention about bounded context intercommunication that would be seen in further chapters. I guess that due to book length you had to shorten it, and seems that that part unfortunately got out of scope. I guess that a good strategy would be to use a messaging service such as RabbitMQ and take the pub-sub route. I am wondering in that scenario, how would you manage sharing the actual event objects between bounded contexts, assuming we're not taking a shared kernel approach. Would you create a new type of events (eg: Integration Events) or the already seen Domain Events would be reused? Thanks, I loved the book by the way. |
Some integration concerns are covered in Chapter 13. It is not published yet and it will be online only. You should have a link at the end of the book in your copy. |
The topic of using different event contracts inside and outside of the context is covered briefly as well. You are on the right track. Remember that persisting new state and publishing events must be done in a transaction. If you use event sourcing, you’re good. Make a reactor that will convert domain events to integration events and publish to the bus. Some people just use EventStore for integration as well. Persistent subscriptions are quite good, handle retries, can scale and you don’t need to worry about the checkpoint. |
Thanks for sharing your feedback, Alexey. With this I'm closing the issue. |
It can be reproduced (but not clearly tested) with following test (put a break point in the when method of the picture class).
You will notice that the following code is executed twice:
Since the handling is an idempotent operation, there is no harm (that's why the test is not failing), but in case of non-idempotency it would give nasty results.
The test:
The text was updated successfully, but these errors were encountered: