Open Tristan107 opened 1 year ago
Same issue here, in my test, domain ports (interfaces) methods can not have domain object as parameter.
Am I missing something?
domainModels
behaves like a setter, i.e. does not extend the internal domainModelPredicate
(and likewiese for domainServices
and applicationServices
). That is, when calling the methods multiple times, previous package identifiers are simply overwritten.
The solution for @Tristan107 was to
domainModels
in one method call, andmappers
and spi
interfaces to applicationServices
and domainServices
, respectively.
@ArchTest
public static final ArchRule onionArchitectureRule = onionArchitecture()
- .domainModels("fr.tristan.demoassurance.domain.entity..")
- .domainModels("fr.tristan.demoassurance.domain.event..")
- .domainServices("fr.tristan.demoassurance.domain.api..")
- .applicationServices("fr.tristan.demoassurance.application.controller")
+ .domainModels("fr.tristan.demoassurance.domain.entity..", "fr.tristan.demoassurance.domain.event..")
+ .domainServices("fr.tristan.demoassurance.domain.api..", "fr.tristan.demoassurance.domain.spi..")
+ .applicationServices("fr.tristan.demoassurance.application.controller..", "fr.tristan.demoassurance.application.mapper..")
.adapter("message", "fr.tristan.demoassurance.infrastructure.message..")
.adapter("persistence-mongodb", "fr.tristan.demoassurance.infrastructure.repository.mongodb..")
.adapter("persistence-mysql", "fr.tristan.demoassurance.infrastructure.repository.mysql..")
A discussion was started in comments on StackOverflow (which is probably better continued here)
Yes but like I said there should be more categories, like "serviceProviderInterfaces" to ensure this is actual onion architecture and not layered architecture with domain depending on persistence like in your example.
Here is the formatted SO question : https://stackoverflow.com/questions/76252658/why-does-this-archunit-test-fails
Here is a raw copy :
I have a demo project which tries to respect strictly clean/onion/hexagonal architecture. Here is how I configure ArchUnit test :
ArchUnit complains about one parameter :
Here is the "guilty" method :
This makes no sense for me because :
I don't see which rule is violated, it's just not explained why a SPI interface should not have a parameter of a domain model type.
I have an other interface in the same
fr.tristan.demoassurance.domain.spi
parent package with asave
method which also have a parameterPoliceAssurance
from "domain models" and ArchUnit doesn't complain about it :