I am trying to come up with a design for an application I am working on.
Here is a basic picture of what I am looking to do. Everything up to the Data Layer
is totally fine but the Data Layer
makes request from the Network Layer
as shown in the picture, and that is one way, from Data Layer
to Network Layer
.
Here is my dilemma. Some network requests need a token to be executed, but how do I get this token in the network layer if I cant access the Data Layer
from Network Layer
The token gets generated by first logging in. So the user starts the login process from the UI Layer
-> Login Service
-> LoginInfoRepository
-> Get User (from network layer)
. Then the token gets cached.
Process of a request that requires token
User executes a process that requires token from UI Layer
-> XXX Service
-> XXRepository
-> Get XXX (from network layer)
; however, the GET XXX
request needs a token
(which was generated from the login process and now it exits in the LoginInfoRepository
) to make the request. How do I get access to that token?? I am confused, maybe I am doing something wrong in this design?
Note: I am trying to adhere to single responsibility principle
.
One way I thought to solve it is to pass the token from the repository to network layer in the constructor but again I am trying to adhere to SRP
and a single repository can only control itself it can't access a different repository such as LoginInfoRepository
Note I am still learning the concept of DDD and all it’s rules so if you feel I have violated the architecture or misused it please feel free to correct me as well.
Edit My understand of DDD is as follows The UI layer is responsible presenting data and accepting user input. If if needs to do any operation, say login. It would call the service in the domain layer, this is responsible on all the business logic including creating/retrieving different data but not single CRUD operations. So the service would call repositories to access the data. And finally the repository would make calls to network layer to get data from different APIs.
I don’t think what I am trying to achieve is impossible but I think I might have tackled the problem incorrectly. I mean apps all around do login and have a JWT that gets passed to the network layer. I am confused to be honest.