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
- Host: GitHub
- URL: https://github.com/tarekmansour/decorator-pattern
- Owner: tarekmansour
- Created: 2023-03-15T20:43:28.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-25T17:29:58.000Z (almost 3 years ago)
- Last Synced: 2025-04-08T06:51:15.305Z (about 1 year ago)
- Topics: csharp, decorator-pattern, design-patterns, dotnet
- Language: C#
- Homepage:
- Size: 17.6 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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")));
```