Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

1. First, accepting the IRestClient interface. The calling application will have to implement an adapter for it (even if it's using the RestSharp library).
2. 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. IRestClient 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?

What I have tried:

Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900