C#C
C#2y ago
M B V R K

Is this DDD Specification a good practice or not?

Hi friends, hope you're all doig well,
I'm working on a project by implementing the DDD (Domain Driven Design),
As you know that one of the core concepts of DDD is the Specification Pattern (Specifications),
I have written the following 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.");
    }
}


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

For more info and definition of the Specification<T> class take a look here :
https://github.com/MbarkT3STO/ExpenovaApp/blob/main/Source/ExpenseService/ExpenseService.Domain/Specifications/Specification.cs
GitHub
Contribute to MbarkT3STO/ExpenovaApp development by creating an account on GitHub.
Was this page helpful?