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