- Decorator pattern is a structural design pattern that allows you to dynamically add new behavior to an existing class, without modifying the original class.
- It's more flexible than inheritance.
- Supports the Single Responsibility Principle, as it allows functionality to be divided between classes with unique areas of concerns
I'm implementing the decorator pattern for caching strategy in this repository within a Product API HttpClient.
register in DI when using ProductClient
outside:
service.AddProductsClient(new Uri(configuration.GetValue<string>("ProductsApi:BaseUrl")));
//register cached client
service.AddCachedProductsClient(new Uri(configuration.GetValue<string>("ProductsApi:BaseUrl")));