[英]Doubts on how to use the reactive paradigm with DDD - Domain repositories
I am working on a project where the DDD methodology is going to be used for the development and, due to the business needs, a reactive programming approach is going to be used.我正在开发一个项目,该项目将使用 DDD 方法进行开发,并且由于业务需求,将使用反应式编程方法。
I am modeling the domain, and some doubts have arisen when I was working on the definition of the repositories.我正在对域进行建模,当我在定义存储库时出现了一些疑问。 I see the problem when implementing the repositories, through an adapter, because using reactive programming, all methods return Uni or Multi (Mutiny. will be used), This is a problem because I am introducing dependencies with the framework in the domain.我在通过适配器实现存储库时看到了问题,因为使用反应式编程,所有方法都返回 Uni 或 Multi(将使用 Mutiny。),这是一个问题,因为我在域中引入了与框架的依赖关系。 which violates DDD principles.这违反了DDD原则。
I have seen some posts on this forum (eg: DDD Java with Spring - Repository returning Mono/Flux ), but I am not confident with the solution proposed.我在这个论坛上看到了一些帖子(例如: DDD Java 和 Spring - Repository 返回 Mono/Flux ),但我对提出的解决方案没有信心。 Has anyone been able to deal with this challenge effectively?有没有人能够有效地应对这一挑战?
You can declare your domain repository interface with generic type:您可以使用泛型类型声明您的域存储库接口:
public interface MyRepositoryOutgoingPort <T> {
T persist(My my);
}
And in reactive (eg Mongo) implementation you can wrap the result:在反应式(例如 Mongo)实现中,您可以包装结果:
@Repository
public interface MyRepositoryMongoImpl
extends ReactiveMongoRepository<My, UUID>,
MyRepositoryOutgoingPort<Mono<My>> {
@Override
default Mono<My> persist(My my) {
Mono<My> savedMy = save(my);
savedMy.subscribe();
return savedMy;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.