Re: [DDD/CQRS] Checks before deleting an entity

104 просмотра
Перейти к первому непрочитанному сообщению

Boris Guéry

не прочитано,
2 июн. 2017 г., 11:44:2502.06.2017
– ddd...@googlegroups.com
As far as a business rule is involved (invariant), your read-model (which is eventually consistent) must not be used.

Maybe you need to distill your design, and make sure your invariants cannot be broken.

Manufacturer cannot be disabled if it has any series linked to it.

Note: I said disabled because I wanted to point you are going to actually do a soft delete. Your aggregate will probably still exists.

However, there is nothing wrong to check if there are series linked to your manufacturer from your read-command before to issue your commands, but you should not trust this information.

I guess your Manufacturer must be aware of the Series linked to it and not the opposite.

--
Boris Guéry - IT Consultant / Software Architect

twitter: @borisguery
mobile:  +33686830312
skype:   borisguery

On Fri, Jun 2, 2017 at 11:54 AM, 'Newm' via DDD/CQRS <ddd...@googlegroups.com> wrote:
I have started experimenting with CQRS/ES and have created a very basic project. The idea is that I need to record details of model cars such as Matchbox, Corgi, Dinky, etc.

I have broken it down into 3 aggregate roots:

Manufacturer (Matchbox, Corgi, Dinky)
Series (Matchbox->Hot Wheels, Matchbox->75s, etc)
Vehicles

A series must have a manufacturer, a vehicle must have a series.

I have created a number of commands and events to allow the creation of manufacturers and series e.g.

CreateManufacturer
CreateSeries
CreateVehicle

Before allowing the user to delete a manufacturer I would like to check that there are no series linked to it.  Similarly I would like to ensure that there are no vehicles linked to a series before allowing it to be deleted.

How should this be handled?  Should I create a service which uses the read models to determine if a manufacturer/series is in use before sending a DeleteManufactuer/DeleteSeries command or should the manufacturer/series domain objects (aggregate roots) internally track the number of items linked to it using the Apply override (i'm using CQRSLite)?

If I go down the domain object path should the CreateSeries command be replaced with a AddSeries method on the manufacturer domain object?

--
You received this message because you are subscribed to the Google Groups "DDD/CQRS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dddcqrs+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/dddcqrs.
For more options, visit https://groups.google.com/d/optout.

Ответить всем
Отправить сообщение автору
Переслать
0 новых сообщений