App Services' Client¶
App Services behave as an ordinary Controller, meaning that their methods are exposed using endpoints, with routes built conventionally, as exposed here.
The Suite framework allows you to auto-generate the App Service's client, with which
you will be able to invoke IAppServices
, through http. Yo can do so by injecting
IAppServiceProxy<TAppService>
and using its Client
property.
In the following example you can see how to inject an auto-generated App Service
client for InspectionsAppService
, using its contract interface named
IInspectionsAppService
.
C# | |
---|---|
It's important to follow these rules for the App Service's to be able have its clients generated properly:
- Do create an contract interface of your App Service class, to be able to inject
auto-generated proxy client. The contract must implement
IAppService
. - Do name your interface as same as your App Service class, plus a leading
I
. For example, given an App Service calledServiceOrdersAppService
, the contract interface must be calledIServiceOrdersAppService
. - Do define
async
methods only,sync
methods are not supported.
Configuring underlying HttpClient¶
As mentioned before, auto-generated client uses HttpClient
under the hood,
which is obtained through IHttpClientFactory
. To provide additional
configuration the underlying HttpClient
used by the auto-generated client
feature, you can either particularize for all clients, by providing a default
configuration, or you can narrow down particularization to apply just to a
specific one.
Let's see an example of a module providing customizations to the underlying HttpClient used by App Service client.
From the example, "basic-sample-client" settings are defined in ConfigureServices
method
to be used as default for any App Service. The HttpClient settings for
IInspectionsAppService
's client are defined inline, in the Setup
method. If
you prefer to provide the HttpClient settings either general or for specific
App Service clients, you must add them using AddHttpClient
method, supplying
the name of the App Service being configured, using kebab-case format. For
example, if we were configuring the IInspectionsAppService
through
IHttpClientFactory
, we would do as follows: