This will help more if you post more specific examples of your aggregates and events. In general, you can create more detailed events if that makes sense in your situation. Then instead of the 1-1 relationship between Command and Event, you will have a 1-N relationship that is fully consistent with the CQRS theory.
So let's give you an example:
CreateInvoice : Command
- InvoiceId
- Customer (10 fields)
- Address (5 more fields)
- InvoceLine[] (where each InvoiceLine also have 10 fields or so)
- Rest of 100 or so fields
InvoiceCreated : Event
- InvoiceId
- Customer (10 fields)
- Address (5 more fields)
- InvoceLine[] (where each InvoiceLine also have 10 fields or so)
- Total
- Rest of 100 or so fields
And in Command Handler:
void Handle(CreateInvoce cmd)
{
var invoice = new Invoice(cmd.InvoiceId, cmd.Customer, cmd.Address, cmd.Lines ....)
uow.Register(invoice);
}
where only one InvoceCreated event will be generated.
Instead, you can have more detailed events:
InvoiceCreated : Event
- InvoiceId
- Customer
- Address
InvoiceLineAdded
- InvoiceId
- Item
- Vat
- Subtotal
- Etc
Then in Command Handler:
void Handle(CreateInvoce cmd)
{
var invoice = new Invoice(cmd.InvoiceId, cmd.Customer, cmd.Address);
foreach (var line in cmd.Lines)
{
invoice.AddLine(line.Item, line.Quantity, line.Price, ...);
}
uow.Register(invoice);
}
Here ctor will raise the InvoiceCreated event, and the AddLine method will raise the InvoiceLineAdded event. You can then have events like InvoiceLineChanged / InvoiceLineRemoved that you can use with updates.
This will allow you to have more detailed events, while maintaining the issuance of coarser commands.
, / PoV.
P.S. , . /-. - . , -. , "" , , ;)?
, .