【发布时间】:2017-11-28 17:24:56
【问题描述】:
我有一个使用领域驱动设计的小型应用程序,现在我想要一个带有翻译的实体。
我在互联网上读到,领域驱动设计的最佳实践是将翻译与模型分开,但我不知道该怎么做。
这是我所拥有的示例:
@Entity
class Product {
@Id
private String id;
private String name;
private String description;
private BigDecimal price;
private BigDecimal originalPrice;
...
}
@Service
class ProductService {
@Autowired
private ProductRepository productRepository;
public List<Product> getAll() {
return productRepository.findAll();
}
public List<Product> getById(String id) {
return productRepository.findById(id);
}
public List<Product> create(ProductDto productDto) {
Product product = new Product(
productDto.getName(),
productDto.getDescription(),
productDto.getPrice(),
productDto.getOriginalPrice()
);
return productRepository.save(product);
}
}
那么我的问题是:
假设我收到了产品 DTO 中的翻译,我想知道如何去做。
感谢并感谢您的帮助。
【问题讨论】:
-
好吧,如果翻译是领域的核心,我认为翻译很可能成为模型的一部分。在我们构建的系统中,每个描述性字符串最终都包裹在
TranslatedTextVO 中。
标签: spring-boot domain-driven-design ddd-repositories ddd-service