Domain service for Image business logic.
Encapsulates complex business rules that don't belong to a single entity. Uses dependency injection for repository access.
const queryRepo: IImagesQueryRepository = new PrismaImagesQueryRepository();const domainService = new ImagesDomainService(queryRepo);try { await domainService.ensureNoDuplicate(path, userId); // Safe to create the image} catch (error) { if (error instanceof DuplicateError) { // Handle duplicate path }} Copy
const queryRepo: IImagesQueryRepository = new PrismaImagesQueryRepository();const domainService = new ImagesDomainService(queryRepo);try { await domainService.ensureNoDuplicate(path, userId); // Safe to create the image} catch (error) { if (error instanceof DuplicateError) { // Handle duplicate path }}
Creates a new ImagesDomainService instance.
The query repository for checking duplicates
Validates that no image with the same path exists for the user.
The path to check for duplicates
The user ID for tenant isolation
When an image with this path already exists
This is a domain invariant check that should be called before creating images.
Domain service for Image business logic.
Remarks
Encapsulates complex business rules that don't belong to a single entity. Uses dependency injection for repository access.
Example
See