You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* - Removed try block to catch and wrap exception in a Result object in DefaultServiceChannel SendAsync methods. Leave it to caller to handle exceptions.
* - simplify empty interface definitions
* - add Open API documentation information to docs
* - change path of OpenApiDocumentation.md
* - add WebResultEndpoint Response Mapping doc
* - update individual readme.md asset files for each package
* - seperate documentation for service endpoint clients
* - bump version
Copy file name to clipboardExpand all lines: docs/EndpointTypes.md
+1-53Lines changed: 1 addition & 53 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,56 +78,4 @@ A ServiceEndpoint has following special traits and constraints:
78
78
- A ServiceEndpoint's request is specific to that endpoint. Each endpoint must have its unique request type.
79
79
- To utilize the advantages of a ServiceEndpoint over other endpoint types, its request and response models have to be shared with clients and therefore has to be in a seperate class library.
80
80
81
-
These restrictions enable clients to call ServiceEndpoints by utilizing a specialized message channel resolved from dependency injection, with only service base address and endpoint's request/response model information. No other client implementation or knowledge about service is required.
82
-
83
-
Have a look at [sample ServiceEndpoint implementations](../samples/ShowcaseWebApi/Features/StoresWithServiceEndpoint) along with [sample client implementation](../samples/Client) and [request/response model shared library](../samples/ShowcaseWebApi.FeatureContracts).
84
-
85
-
## ServiceEndpoint clients
86
-
87
-
A client application consuming ServiceEndpoints, creates service channel registry entries for those endpoints (remote services) during application startup, basically mapping which request message type will be sent by using which HttpClient configuration (base address, timeout, handlers, resilience definitions, etc.). Service channel utilizes IHttpClientFactory and HttpClient underneath and is configured similarly.
88
-
89
-
Registration can be done either for all service requests in an assembly...
These restrictions enable clients to call ServiceEndpoints by utilizing a specialized message channel resolved from dependency injection, see [ServiceEndpoint Clients](ServiceEndpointClients.md) documentation for details.
API documentation follows the same approach as .NET Core Minimal APIs. You only need to use your preferred documentation generator; no additional packages are required.
A client application can consume ServiceEndpoints by utilizing a specialized message channel resolved from dependency injection. Only service's base address and endpoint's request/response model information are needed. No other client implementation or service specific knowledge is required.
4
+
5
+
## ⚙️ Workflow
6
+
7
+
The workflow for consuming ServiceEndpoints from a client application consists of two main steps: **registration** and **consumption**.
8
+
9
+
### Registration
10
+
11
+
A client application registers service endpoints with a specific HttpClient configuration (such as base address, timeout, handlers, resilience policies, etc.) during application startup. This can be performed for all service requests within an assembly or for each request type individually.
12
+
13
+
To register all service requests in an assembly at once:
>1. The client name is used to resolve the correct HttpClient configuration for each request type.
50
+
>2. Service channel utilizes IHttpClientFactory and HttpClient underneath and is configured similarly.
51
+
52
+
### Comsumption
53
+
54
+
Remote `ServiceEndpoints` can be called by resolving an `IServiceChannel` instance from dependency injection and invoking the `SendAsync` method with the desired request object.
`WebResultEndpoint` transforms the result returned by its `HandleAsync` method —a business result— into appropriate HTTP status code and response format, providing consistent and type-safe API behavior. This process relies on a default result-to-response mapper.
4
+
5
+
There are several ways to customize how responses are mapped:
6
+
7
+
One way to customize response mapping is by overriding the ConvertResultToResponseAsync method. This method is invoked after HandleAsync to transform the business result into an HTTP response. By default, it uses the IResultToResponseMapper service for this conversion, but you can override it to implement your own mapping logic.
Another option is to implement your own `IResultToResponseMapper` and register it in the DI container as a keyed service using a string key.
41
+
You can then apply the `[ResultToResponseMapper("MyMapperKey")]` attribute to any `WebResultEndpoint`-based endpoint to have it use your custom mapper instead of the default one.
42
+
43
+
```csharp
44
+
// Lifetime of the mapper is defined as singleton only for example purposes, it can be any lifetime
It is also possible to replace default mapper for all endpoints by registering your mapper as the default mapper before invoking any variant of `AddModEndpoints` method.
72
+
73
+
```csharp
74
+
varbuilder=WebApplication.CreateBuilder(args);
75
+
76
+
77
+
// Register your custom mapper as the default mapper
78
+
// Lifetime of the mapper is defined as singleton only for example purposes, it can be any lifetime
0 commit comments