Integration with the data layer
The response from our APIs may or may not look like our domain models. Instead, their structure can resemble the fields that the UI or Views need to bind; hence, it is recommended to create a separate set of POCO classes that integrate with our UI. These POCOs are known as Data Transfer Objects (DTOs).
In this section, we will implement our DTOs' domain logic integrating with the data layer and integrate the cache services discussed in Chapter 8, All You Need to Know about Caching, using the Cache-Aside pattern, and then—finally—implement the required RESTful APIs using controllers and actions. Along the way, we will use the HTTPClient factory for our service-to-service communication, and the AutoMapper library for mapping domain models to DTOs.
We will pick a product service that is part of Packt.Ecommerce.Product, a web API project using .NET 6, and discuss its implementation in detail. By the end of this section, we will have...