{"id":25232122,"url":"https://github.com/mreshboboyev/decorator-pattern","last_synced_at":"2025-04-05T16:20:17.501Z","repository":{"id":272260402,"uuid":"915994055","full_name":"MrEshboboyev/decorator-pattern","owner":"MrEshboboyev","description":"A C# repository demonstrating the Decorator Pattern in .NET, showcasing its use for extending functionality dynamically, including examples of in-memory operations, logging, and service registration using both manual techniques and Scrutor.","archived":false,"fork":false,"pushed_at":"2025-03-02T07:58:44.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-02T08:27:50.353Z","etag":null,"topics":["c-sharp","clean-code","decorator-pattern","dependency-injection","design-patterns","dotnet-core","in-memory","logging","oop","scrutor","software-architecture"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MrEshboboyev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-13T08:54:32.000Z","updated_at":"2025-03-02T07:58:48.000Z","dependencies_parsed_at":"2025-01-13T10:26:08.772Z","dependency_job_id":"6048a6ba-28a9-470f-b708-d5f3670a069c","html_url":"https://github.com/MrEshboboyev/decorator-pattern","commit_stats":null,"previous_names":["mreshboboyev/decorator-pattern"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrEshboboyev%2Fdecorator-pattern","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrEshboboyev%2Fdecorator-pattern/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrEshboboyev%2Fdecorator-pattern/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrEshboboyev%2Fdecorator-pattern/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MrEshboboyev","download_url":"https://codeload.github.com/MrEshboboyev/decorator-pattern/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247362438,"owners_count":20926780,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-sharp","clean-code","decorator-pattern","dependency-injection","design-patterns","dotnet-core","in-memory","logging","oop","scrutor","software-architecture"],"created_at":"2025-02-11T12:55:18.133Z","updated_at":"2025-04-05T16:20:17.495Z","avatar_url":"https://github.com/MrEshboboyev.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🎨 Decorator Pattern in .NET  \n\nThis repository provides an in-depth implementation of the **Decorator Pattern** in **.NET C#**. The Decorator Pattern is a structural design pattern that allows behavior to be added to an individual object dynamically, without affecting the behavior of other objects of the same class.  \n\nIn this project, you'll explore:  \n- Manual and **Scrutor**-based service registration for decorators.  \n- Practical examples including **logging** and **in-memory operations**.  \n- Clean and maintainable code adhering to **OOP principles**.  \n\n## 🌟 Features  \n\n### Core Concepts  \n- **Decorator Pattern**: Dynamically add functionality to objects without altering their structure.  \n- **Manual and Scrutor-based Registration**: Learn two approaches for setting up decorators in .NET.  \n- **Practical Use Cases**: Logging, caching, and in-memory operations.  \n\n### Tools and Libraries  \n- **Scrutor**: A library for assembly scanning and automatic decorator registration in .NET.  \n- **Dependency Injection (DI)**: Utilize .NET’s built-in DI container to manage service lifetimes and decorators.  \n\n## 📂 Repository Structure  \n\n```\n📦 src  \n ┣ 📂 DecoratorPattern             # Core implementation of the pattern  \n ┣ 📂 WithoutDecoratorPattern      # Core implementation without pattern  \n```  \n\n## 🛠 Getting Started  \n\n### Prerequisites  \nEnsure you have the following installed:  \n- .NET Core SDK  \n- A modern C# IDE (e.g., Visual Studio or JetBrains Rider)  \n\n### Step 1: Clone the Repository  \n```bash  \ngit clone https://github.com/MrEshboboyev/decorator-pattern.git  \ncd decorator-pattern  \n```  \n\n### Step 2: Run the Project  \n```bash  \ndotnet run --project src/DecoratorPattern  \n```  \n\n### Step 3: Explore the Code  \nNavigate through the codebase to see the decorator pattern in action with logging, caching, and service registrations.  \n\n## 📖 Code Highlights  \n\n### Manual Registration Example  \n```csharp  \nservices.AddTransient\u003cIService, Service\u003e();  \nservices.AddTransient\u003cIService\u003e(provider =\u003e  \n{  \n    var original = provider.GetRequiredService\u003cService\u003e();  \n    return new LoggingDecorator(original);  \n});  \n```  \n\n### Scrutor-Based Registration Example  \n```csharp  \nservices.Scan(scan =\u003e scan  \n    .FromAssemblyOf\u003cService\u003e()  \n    .AddClasses(classes =\u003e classes.AssignableTo\u003cIService\u003e())  \n    .AsImplementedInterfaces()  \n    .WithTransientLifetime()  \n    .Decorate\u003cIService, LoggingDecorator\u003e());  \n```  \n\n### Decorator Example: Logging  \n```csharp  \npublic class LoggingDecorator : IService  \n{  \n    private readonly IService _innerService;  \n\n    public LoggingDecorator(IService innerService)  \n    {  \n        _innerService = innerService;  \n    }  \n\n    public void PerformOperation()  \n    {  \n        Console.WriteLine(\"Logging: Before operation.\");  \n        _innerService.PerformOperation();  \n        Console.WriteLine(\"Logging: After operation.\");  \n    }  \n}  \n```  \n\n## 🌐 Use Cases  \n\n### 1. Logging Decorator  \nLogs messages before and after an operation is performed.  \n\n### 2. Caching Decorator  \nStores results of expensive operations in memory for faster subsequent access.  \n\n### 3. In-Memory Data Processing  \nDemonstrates in-memory operations to showcase how decorators can extend functionality dynamically.  \n\n\n## 🌟 Why This Project?  \n1. **Learn Design Patterns**: Understand the practical use of the decorator pattern in modern software.  \n2. **Clean and Extensible Code**: Build solutions that adhere to OOP principles and are easy to extend.  \n3. **Real-World Examples**: Explore logging and caching as practical applications of decorators.  \n4. **Modern Tools**: Learn how to leverage **Scrutor** for simplified registration.  \n\n## 🏗 About the Author  \nThis project was developed by [MrEshboboyev](https://github.com/MrEshboboyev), a software developer passionate about clean code, design patterns, and scalable architectures.  \n\n## 📄 License  \nThis project is licensed under the MIT License. Use it to enhance your projects or learn more about design patterns in .NET.  \n\n## 🔖 Tags  \nC#, .NET, Decorator Pattern, Design Patterns, Scrutor, Dependency Injection, Logging, In-Memory, Software Architecture, OOP, Clean Code  \n\n---  \n\nFeel free to suggest new features, raise issues, or fork the project to contribute! 🚀  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmreshboboyev%2Fdecorator-pattern","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmreshboboyev%2Fdecorator-pattern","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmreshboboyev%2Fdecorator-pattern/lists"}