L
L
llexus2014-07-01 14:00:22
.NET
llexus, 2014-07-01 14:00:22

Architectural question on Web API. How to properly share a token between instances?

Greetings.
I have very little experience in these matters, so I decided to turn to knowledgeable people so that later it would not be excruciatingly painful. I am writing a modest client for WP for one site using a self-written API. I started everything from a draft version, but then it went off and on and it grew to an indigestible size. At the moment, to use the API, I create 1 global instance of the class of this API, authenticate through it, and it stores the token in itself. Then I simply pull the methods of this instance, for example:
myapi.LikeRecord(Record rec);
Accordingly, the method inside lacks a token and LikeCompleted passes through the output.
I would like it to look a little different for me: I want to make Record more independent and use
Recrod.Like();
but how to properly organize token sharing in this case? Only some kind of static class comes to mind, but what if this is not the right direction?
Prompt at least in what direction to me to dig.
Thank you very much!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
ostapbender, 2014-07-01
@ostapbender

Leave as is. Record.Like() is a clear violation of SRP . Plus, an extra headache about "how can I create an object of the Record class" - and there it is not far from factories with decorators and other enterprises.

A
Alexey Kulakov, 2014-07-01
@carbon88

I think you can use the Singleton pattern.

A
Alexander, 2014-07-01
@SashaSkot

Static Class, for example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question