-
Notifications
You must be signed in to change notification settings - Fork 18
Services
This class can be used to abstract away Http requests to an endpoint. The BaseHttpService base class simplifies working with REST APIs in a reliable manner by encapsulating the correct usage of HttpClient, handling common tasks such as serialization and implementing recommended cloud design patterns such as retry and circuit breaker.
If you run into issues with the Http messages and responses being sent and received, the BaseHttpService
provides a couple of callbacks that can be especially useful.
-
HttpRequestMessageSent
allows inspection of theHttpRequestMessage
that is being sent from the service. -
HttpResponseMessageReceived
allows inspection of theHttpResponseMessage
received by the service. Note: this is the raw response, there is no deserialization done at this point.
An Example:
var service = new MyHttpService();
#if DEBUG
service.HttpRequestMessageSent += request => Debug.WriteLine(request);
service.HttpResponseMessageReceived += response => Debug.WriteLine(response);
#endif
The MobCAT library includes a ServiceContainer class as a light-weight and simple mechanism for implementing the service locator IoC (Inversion of Control) design pattern. This enables both platform-specific and platform-agnostic components to be registered and subsequently resolved via a common interface within shared code. It also enables mock services to be registered for UI test or unit test purposes.
The Bootstrap class centralizes the process of initializing and registering the respective services using the ServiceContainer class. Platform-specific startup actions can also be invoked using the optional Func parameter in the Begin method. The Begin method is called from the AppDelegate for iOS, and MainActivity for Android respectively.