dimanche 1 décembre 2019

How to design domain driven design application service for aggregate?

I am new at domain driven design, so I want to ask about using application service for aggregate root.

I have an aggregate root.

public class Product: AggreagateRoot{
    publis int Id {get; set;}
    publis string Name {get; set;}

    public ICollection<Comment> Comments {get; set;}
    public ICollection<Types> Types {get; set;}
}

The comments and Types are related with Product. So a Comment or a Type doesn't mean anything by itself.

So I am creating an application service for product.

public class ProductService {

    public Product Create(ProductCommand command){
        .....
        ...
    }

    public Product Update(ProductCommand command){
        .....
        ...
    }

}

Should I add methods for create and update Comments and Types in ProductService like following?

public class ProductService {

    public Product Create(ProductCommand command){
        .....
        ...
    }

    public Product Update(ProductCommand command){
        .....
        ...
    }

    public Comment Create(CommantCommand command){
        var product = _context.Product.Find(command.ProductId);

        product.Comments.add(new Comment(command.message));

        _context.SaveChanges();
        .....
        ...
    }

    public Comment Update(CommantCommand command){
        var comment = _context.Comments.Find(command.Id);

        comment.message = command.message;

        _context.SaveChanges();
        .....
        ...
    }       
}

Or Should I create seperate services for Comment and Types?

Aucun commentaire:

Enregistrer un commentaire