Shallow copies of Session instances to promote composition? #3627
ursusursus
started this conversation in
General
Replies: 1 comment 4 replies
-
Turned this into a discussion. This will not be a feature Alamofire adopts, as we already have many ways of composing interceptors and other features. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a case where I have multiple logical levels of network apis - pubic, semi-public, private, where private inherits semi-public, and semi-public inherits from public.
Each adds its own interceptors to attach headers and other behavior and should inherit configuration of the parent.
In OkHttp in java/kotlin world this is done via creating a shallow copy on the okhttclient instance
Since its a shallow copy, threadpools are not duplicated, so its not a performance/memory issue.
If I setup instances this way, then they can be simply injected into feature api interface and get the "feature" developer gets all the desired shared behavior for free, which is great.
So, mostly a question, since I dont believe this is supported. I looked at SessionDelegate which sounded what I want but doesnt seem to do so.
Best api would look like this
I can sort of emulate this my self by collecting the interceptors, but then I'd have three separate Session instances, which I believe triples the dispatch queues, right?
I'm aware of request level interceptors, but then the feature developer needs to take care to attach them, which is error prone
Beta Was this translation helpful? Give feedback.
All reactions