php-ddd icon indicating copy to clipboard operation
php-ddd copied to clipboard

Properties on Domain Events

Open JorgeOnrubiaMojica opened this issue 3 years ago • 3 comments

Hi

I'm in love with this project. The debate is so rich.

I have a question or various questions.

How do you model your domain events? I mean. I have an aggregate in one BC named Address that holds references to other Aggregates by theirs ids, like a normal aggregate: CityId, StateId, etc.... But in another BC the same Address aggregate I would like to represent the Address like various Value Objects, I dont care about your ids. Address has CityName and StateName.

The problem is my Domain Event, AddressCreated only hold the ids of the aggregate fresh created, I mean, the AddressId, CityId and StateId, but in the other BC I need the names.

JorgeOnrubiaMojica avatar Jun 08 '22 16:06 JorgeOnrubiaMojica

Hello,

If AddressCreated event doesn't have all the information you need then you'll probably need to provide more events like CityCreated, StateCreated... and so on, so the other BC has all the data to populate his projection.

AlbertMorenoDEV avatar Jun 09 '22 14:06 AlbertMorenoDEV

Hi.

I don't want to replicate all the address structure on the second BC. I don't need to known that CityId with id 1 is NYC or so. I only need in the second BC a Value object that represent the Address of a Client.

Yesterday, thinking on the best solution, came up one idea. When I consume the event in the second BC, my ACL can do a HTTP call to the first BC to transform the ids of the event in my Address Value Object on my second BC.

JorgeOnrubiaMojica avatar Jun 09 '22 14:06 JorgeOnrubiaMojica

This might work as long as you handle outages properly, I usually try to avoid direct calls between BC for it, but depending on the project can be a valid solution for sure.

Cheers

AlbertMorenoDEV avatar Jun 09 '22 14:06 AlbertMorenoDEV