I am new to design patterns and I'm trying to write a REST client library using .NET Standard
for a service that delivers application/json.
However, the RestSharp
doesn't support .NET Standard
yet (there is an open issue on github).
To be able to use it in the future, and to adhere to “program to an interface, not an implementation” principle, I am going to create a public interface (IRestClient
), which will encapsulate the needed functionality: the Execute()
and ExecuteAsync()
methods.
The constructor of the main class of my library will have two overloads:
- First, accepting the
IRestClient
interface. The calling application will have to implement an adapter for it (even if it's using theRestSharp
library). - Parameter-less (as a fallback) which will use the built-in
HttpClient
-based implementation.
What I'm struggling with is that each class has it's own dependencies on both of these methods (e.g. RestClient
depends on IRestRequest
and IRestResponse
, and for HttpClient
it's HttpRequestMessage
and HttpResponseMessage
). These dependencies have other dependencies and so on.
Is there a way I can create a common interface for these methods without re-writing all the dependent interfaces?
Aucun commentaire:
Enregistrer un commentaire