ardalis / pluralsight-ddd-fundamentals

Sample code for the Pluralsight DDD Fundamentals course by Julie Lerman and Steve "ardalis" Smith
MIT License
901 stars 318 forks source link

Invalid usage of Schedule / Appointment? #77

Open ekallaur opened 3 months ago

ekallaur commented 3 months ago

In the FrontDesk/src/FrontDesk.Core/Handlers/EmailConfirmationHandler.cs

var appointmentToConfirm = schedule.Appointments.FirstOrDefault(a => a.Id == appointmentConfirmedEvent.AppointmentId);

appointmentToConfirm.Confirm(appointmentConfirmedEvent.DateOccurred);

This looks like manipulation of the Aggregate internals by bypassing Aggregate itself. In this way Schedule aggregate can not guarantee data integrity. I'm afraid that such example can lead to incorrect understanding of the Aggregate and its purpose.

Shouldn't be:

schedule.ConfirmAppointment(appointmentConfirmedEvent.AppointmentId, appointmentConfirmedEvent.DateOccurred);

OR

schedule.MarkAppointmentAsConfirmed(appointmentConfirmedEvent.AppointmentId, appointmentConfirmedEvent.DateOccurred);