From 106acedce8ab57e3d1d9bf6252d5d8350205bd26 Mon Sep 17 00:00:00 2001 From: Robert van Diest Date: Fri, 27 Mar 2026 16:49:28 +0100 Subject: [PATCH] refactor(domain): introduce ReservationFactory for reconstitution Replace the Reconstitute static method on Reservation with a dedicated ReservationFactory class. The reconstitution constructor is now internal, restricting direct instantiation to within the domain assembly while keeping the factory as the explicit entry point for rehydrating from storage. Co-Authored-By: Claude Sonnet 4.6 --- .../src/Randall.Domain/Reservations/Reservation.cs | 7 +------ .../Randall.Domain/Reservations/ReservationFactory.cs | 9 +++++++++ .../Persistence/Mappers/ReservationMapper.cs | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 src/backend/src/Randall.Domain/Reservations/ReservationFactory.cs diff --git a/src/backend/src/Randall.Domain/Reservations/Reservation.cs b/src/backend/src/Randall.Domain/Reservations/Reservation.cs index 7f4b322..16ec33f 100644 --- a/src/backend/src/Randall.Domain/Reservations/Reservation.cs +++ b/src/backend/src/Randall.Domain/Reservations/Reservation.cs @@ -13,12 +13,7 @@ public class Reservation : Entity public ReservationStatus Status { get; private set; } public DateTime CreatedAt { get; private set; } - public static Reservation Reconstitute( - Guid id, Guid workplaceId, string employeeEmail, string employeeName, - DateOnly date, ReservationStatus status, DateTime createdAt) => - new(id, workplaceId, employeeEmail, employeeName, date, status, createdAt); - - private Reservation( + internal Reservation( Guid id, Guid workplaceId, string employeeEmail, string employeeName, DateOnly date, ReservationStatus status, DateTime createdAt) : base(id) { diff --git a/src/backend/src/Randall.Domain/Reservations/ReservationFactory.cs b/src/backend/src/Randall.Domain/Reservations/ReservationFactory.cs new file mode 100644 index 0000000..887e45f --- /dev/null +++ b/src/backend/src/Randall.Domain/Reservations/ReservationFactory.cs @@ -0,0 +1,9 @@ +namespace Randall.Domain.Reservations; + +public static class ReservationFactory +{ + public static Reservation Reconstitute( + Guid id, Guid workplaceId, string employeeEmail, string employeeName, + DateOnly date, ReservationStatus status, DateTime createdAt) => + new(id, workplaceId, employeeEmail, employeeName, date, status, createdAt); +} diff --git a/src/backend/src/Randall.Infrastructure/Persistence/Mappers/ReservationMapper.cs b/src/backend/src/Randall.Infrastructure/Persistence/Mappers/ReservationMapper.cs index 621ce91..29026a9 100644 --- a/src/backend/src/Randall.Infrastructure/Persistence/Mappers/ReservationMapper.cs +++ b/src/backend/src/Randall.Infrastructure/Persistence/Mappers/ReservationMapper.cs @@ -6,7 +6,7 @@ namespace Randall.Infrastructure.Persistence.Mappers; public static class ReservationMapper { public static Reservation ToDomain(ReservationRecord record) => - Reservation.Reconstitute( + ReservationFactory.Reconstitute( record.Id, record.WorkplaceId, record.EmployeeEmail,