An open API service indexing awesome lists of open source software.

https://github.com/tarekmansour/decorator-pattern

Implement decorator pattern for caching strategy
https://github.com/tarekmansour/decorator-pattern

csharp decorator-pattern design-patterns dotnet

Last synced: 11 months ago
JSON representation

Implement decorator pattern for caching strategy

Awesome Lists containing this project

README

          

# Decorator-Pattern

- 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

## Usage
I'm implementing the decorator pattern for caching strategy in this repository within a Product API HttpClient.

### DI

register in DI when using `ProductClient` outside:

```c#
service.AddProductsClient(new Uri(configuration.GetValue("ProductsApi:BaseUrl")));

//register cached client
service.AddCachedProductsClient(new Uri(configuration.GetValue("ProductsApi:BaseUrl")));
```