3

In my application the network implementation (particularly a HTTP request interceptor) requires an authorization token stored in local persistent storage.

Now, following clean architecture, both network implementation and persistent storage are in the outer most, the framework layer.

The access token can be retrieved via a repository (where the implementation is in the gateway/interface adapters layer and the repository interface is in the inner-most/entity layer.

How should the control flow be in my scenario? Should it go

  1. via a use case, since, in the ring diagram, the use case layer entirely encapsulates the entity layer
  2. via the repository interface and skip the use case layer?

As counter arguments of 1 I see that

  • I require a "get access token" use case, which is not a real use case from the user perspective.
  • If the use case layer always encapsulates the entity layer, is it ok that the repository interface is in the entity layer but the implementation only in the interface adapters layer (skipping the use case layer)?

As counter argument of 2 I see that the use case layer is only between entities and user facing interfaces (controllers, presenters) but not between entities and data gateways - meaning the use cases layer does not actually fully encapsulate the entity layer, which would mean the ring representation of the layers is not accurate.

Peter F
  • 3,633
  • 3
  • 33
  • 45

1 Answers1

2

As I understand Clean architecture and have realized it in my applications the repository interfaces are always in the use case layer not in the entities layer.

Furthermore I would keep access token handling in the adapters layer if access token handling is not part of your applications core business logic.

plainionist
  • 2,950
  • 1
  • 15
  • 27
  • [Relevant thread](https://groups.google.com/d/msg/clean-code-discussion/mvP_NR2MUPc/wrkHHxzkDQAJ) with an answer from Uncle Bob himself. – Sufian Jun 22 '20 at 05:36
  • However, to answer the question of where to put the validation logic, I think [this answer](https://stackoverflow.com/a/59986346/1276636) is very insightful. – Sufian Jun 22 '20 at 05:55