The dependency rule in Clean Architecture states that:
... that source code dependencies can only point inwards.
I now came across a problem that I cannot figure out myself.
Lets assume I have a module with application business rules abr
and 2 modules for services that implement interfaces from abr
.
+---------+
| abr | Business Layer (defines interfaces
+---------+ 'Service1' and 'Service2')
+----^ ^---+
- - -|- - - - - - - - - |- - - - -
| |
+-----+----+ +-----+----+
| service1 | | service2 | Dependencies (implement Interfaces
+----------+ +----------+ define in abr)
Now the 2 services use the networking library OkHttp
and should use the same user agent string for their requests.
Unfortunately I do not how to achieve this nicely.
Possibilities are:
- Create a module
sharedokhttpconfig
that both service depend on
This would violate the depdency rule - Put the code in abr
This would violate thatabr
should not know about networking or even that the services use okhttp - Duplicate the code to set the user agent in both services
Code duplication is bad
Another example would be that the project has 2 different UI modules that are fundamentally different but some logic in them would be the same.
Like formatting the address of a user.
Any suggestions on how to handle this?
To clarify why I think it would violate the dependency rule.
The abr
is the middle of my application, it should not know about UI or anything else, so all dependencies must point int its direction.
But when I add a module that the 2 modules depend on it seems to me that they are pointing outwards.
+---------+
| abr |
+---------+
+----^ Inwards ^---+
| |
+-----+----+ +-----+----+
| service1 | | service2 |
+----------+ +----------+
| Outwards? |
+----v v---+
+---------+
| snbl | snbl = share non-business logic
+---------+
Or is doing it that way ok because from the perspective of abr
nothing has changed?