Hi friends, hope you're all doig well, I'm working on a project by implementing the
DDD
DDD
(
Domain Driven Design
Domain Driven Design
), As you know that one of the core concepts of
DDD
DDD
is the
Specification Pattern
Specification Pattern
(Specifications), I have written the following
Specification
Specification
:
/// <summary>/// Represents a specification that checks if a category with the same name for the same user already exists./// </summary>public class IsUniqueCategoryNameSpecification: Specification<Category>{ readonly ICategoryUniquenessChecker _categoryUniquenessChecker; public IsUniqueCategoryNameSpecification(ICategoryUniquenessChecker categoryUniquenessChecker) { _categoryUniquenessChecker = categoryUniquenessChecker; } protected override void ConfigureConditions() { AddCondition(category => category.Id == Guid.Empty ? _categoryUniquenessChecker.IsUniqueCategoryNameAsync(category.Name, category.UserId).Result : _categoryUniquenessChecker.IsUniqueCategoryNameAsync(category.Id, category.Name, category.UserId).Result, "Category name must be unique."); }}
/// <summary>/// Represents a specification that checks if a category with the same name for the same user already exists./// </summary>public class IsUniqueCategoryNameSpecification: Specification<Category>{ readonly ICategoryUniquenessChecker _categoryUniquenessChecker; public IsUniqueCategoryNameSpecification(ICategoryUniquenessChecker categoryUniquenessChecker) { _categoryUniquenessChecker = categoryUniquenessChecker; } protected override void ConfigureConditions() { AddCondition(category => category.Id == Guid.Empty ? _categoryUniquenessChecker.IsUniqueCategoryNameAsync(category.Name, category.UserId).Result : _categoryUniquenessChecker.IsUniqueCategoryNameAsync(category.Id, category.Name, category.UserId).Result, "Category name must be unique."); }}
Please could you tell me if this is a good implementation for a specification, or this just wrong manner, because this is the first time I write a specification that needs to deal with database?
Please share with me your experience guys, and massive thanks in advance <3