ConstCreates a new unexported book entity with its domain event.
As the aggregate root, Book is the only entry point for creating and managing book entities. All book-related operations must go through this factory to ensure domain invariants are maintained.
Provides immutable entity creation following DDD patterns. All returned entities are frozen using Object.freeze(). Returns a tuple of [entity, event] for domain event dispatching.
// Create a new unexported book with its domain event
const [book, event] = bookEntity.create({
userId: makeUserId("user-123"),
isbn: makeISBN("978-4-06-521234-5"),
title: makeBookTitle("The Pragmatic Programmer"),
caller: "addBook",
});
// Persist and dispatch event
await repository.create(book);
await eventDispatcher.dispatch(event);
BooksDomainService for invariant validation (duplicate ISBN check)
Factory object for Book domain entity operations.
This is the Aggregate Root for the Books bounded context.