{"id":25232132,"url":"https://github.com/mreshboboyev/factory-pattern","last_synced_at":"2026-03-01T23:31:36.890Z","repository":{"id":268922677,"uuid":"905865524","full_name":"MrEshboboyev/factory-pattern","owner":"MrEshboboyev","description":"A .NET application implementing the Factory Pattern to generate invoices in various formats (PDF, TXT, CSV). Utilizes QuestPDF for creating professional PDF documents and the Repository Pattern for organized and maintainable data access.","archived":false,"fork":false,"pushed_at":"2024-12-19T18:42:33.000Z","size":10,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-11T12:55:15.937Z","etag":null,"topics":["aspnet-core","csv","design-patterns","dotnet-core","factory-pattern","file-generation","invoice-generation","pdf-generation","questpdf","repository-pattern","text"],"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":"2024-12-19T17:16:07.000Z","updated_at":"2025-02-08T21:13:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"5750f8c3-c831-4130-8ce1-85384f6e12f3","html_url":"https://github.com/MrEshboboyev/factory-pattern","commit_stats":null,"previous_names":["mreshboboyev/factorypattern","mreshboboyev/factory-pattern"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrEshboboyev%2Ffactory-pattern","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrEshboboyev%2Ffactory-pattern/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrEshboboyev%2Ffactory-pattern/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrEshboboyev%2Ffactory-pattern/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MrEshboboyev","download_url":"https://codeload.github.com/MrEshboboyev/factory-pattern/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247362461,"owners_count":20926788,"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":["aspnet-core","csv","design-patterns","dotnet-core","factory-pattern","file-generation","invoice-generation","pdf-generation","questpdf","repository-pattern","text"],"created_at":"2025-02-11T12:55:19.269Z","updated_at":"2026-03-01T23:31:36.882Z","avatar_url":"https://github.com/MrEshboboyev.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Factory Pattern Showcase: Advanced Implementation\n\nThis project demonstrates a sophisticated .NET implementation of the Factory Pattern to generate invoices in multiple file formats (PDF, TXT, and CSV). It showcases the true power and flexibility of the Factory Pattern in enterprise-level applications.\n\n## 🚀 Key Features\n\n### Factory Pattern Excellence\n- **Advanced Factory Implementation**: Fully-featured factory with logging, validation, and extensibility\n- **Decoupled Architecture**: Client code is completely decoupled from concrete implementations\n- **Centralized Object Creation**: All object instantiation logic is centralized in the factory\n- **Easy Extensibility**: Adding new formats requires minimal code changes\n- **Dependency Injection Integration**: Seamless integration with .NET DI container\n\n### API Documentation\n- **NSwag Integration**: Comprehensive API documentation with Swagger UI\n- **Interactive API Testing**: Built-in Swagger UI for testing endpoints\n- **Detailed Endpoint Documentation**: Rich documentation for all API endpoints\n\n### Format Generation\n- **PDF Generation**: Professional-grade PDF documents using QuestPDF\n- **CSV Generation**: Structured comma-separated data format\n- **TXT Generation**: Simple text-based invoice output\n\n## 🏗️ Architecture Overview\n\nThe Factory Pattern implementation in this project demonstrates several advanced concepts:\n\n1. **Interface-Based Design**: All generators implement the [IInvoiceGenerator](FactoryPattern.API/Abstracts/IInvoiceGenerator.cs) interface\n2. **Factory Interface**: The [IInvoiceGeneratorFactory](FactoryPattern.API/Abstracts/IInvoiceGeneratorFactory.cs) defines the contract for creating generators\n3. **Concrete Factory**: The [InvoiceGeneratorFactory](FactoryPattern.API/Factories/InvoiceGeneratorFactory.cs) implements the factory logic with additional utility methods\n4. **Dependency Injection**: All components are registered with the .NET DI container for proper lifecycle management\n\n## 📦 Prerequisites\n\n- [.NET 9.0 or higher](https://dotnet.microsoft.com/download)\n\n## 🛠️ Installation\n\n1. Clone the repository:\n   ```bash\n   git clone https://github.com/MrEshboboyev/FactoryPattern.git\n   ```\n2. Navigate to the project directory:\n   ```bash\n   cd FactoryPattern\n   ```\n3. Restore dependencies:\n   ```bash\n   dotnet restore\n   ```\n\n## 🚀 Usage\n\n### Running the Application\n\nStart the application:\n```bash\ncd FactoryPattern.API\ndotnet run\n```\n\nThe application will start on `http://localhost:5143` by default.\n\n### API Endpoints\n\n#### Generate Invoice\n```\nGET /api/invoice/{id:guid}/{format}\n```\nGenerates an invoice in the specified format using the Factory Pattern.\n\nParameters:\n- `id`: The unique identifier for the invoice (GUID)\n- `format`: The format in which to generate the invoice (Pdf, Txt, Csv)\n\nExample:\n```\nGET /api/invoice/123e4567-e89b-12d3-a456-426614174000/Pdf\n```\n\n#### Get Supported Formats\n```\nGET /api/invoice/formats\n```\nReturns a list of all invoice formats supported by the Factory Pattern implementation.\n\n### Factory Pattern in Action\n\nThe application uses the Factory Pattern to create appropriate invoice generators based on the requested format:\n\n```csharp\n// Client code is completely decoupled from concrete implementations\nvar generator = invoiceGeneratorFactory.CreateInvoiceGenerator(format);\nvar invoiceData = generator.GenerateInvoice(id);\nvar contentType = generator.GetContentType();\n\nvar fileName = $\"Invoice_{id}.{format.ToString().ToLower()}\";\nreturn Results.File(invoiceData, contentType, fileName);\n```\n\n## 🔧 Extending the Factory Pattern\n\nTo add support for a new file format:\n\n1. Create a new class implementing the [IInvoiceGenerator](FactoryPattern.API/Abstracts/IInvoiceGenerator.cs) interface:\n   ```csharp\n   public class ExcelInvoiceGenerator : IInvoiceGenerator\n   {\n       public byte[] GenerateInvoice(Guid invoiceId)\n       {\n           // Implementation for generating Excel invoice\n       }\n       \n       public string GetContentType() =\u003e \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\";\n   }\n   ```\n\n2. Add the new file type to the [InvoiceFormat](FactoryPattern.API/Enums/InvoiceFormat.cs) enum:\n   ```csharp\n   public enum InvoiceFormat\n   {\n       Pdf, \n       Txt,\n       Csv,\n       Excel  // New format\n   }\n   ```\n\n3. Update the [InvoiceGeneratorFactory](FactoryPattern.API/Factories/InvoiceGeneratorFactory.cs) to include the new type:\n   ```csharp\n   public IInvoiceGenerator CreateInvoiceGenerator(InvoiceFormat invoiceFormat)\n   {\n       return invoiceFormat switch\n       {\n           InvoiceFormat.Pdf =\u003e _serviceProvider.GetRequiredService\u003cPdfInvoiceGenerator\u003e(),\n           InvoiceFormat.Txt =\u003e _serviceProvider.GetRequiredService\u003cTxtInvoiceGenerator\u003e(),\n           InvoiceFormat.Csv =\u003e _serviceProvider.GetRequiredService\u003cCsvInvoiceGenerator\u003e(),\n           InvoiceFormat.Excel =\u003e _serviceProvider.GetRequiredService\u003cExcelInvoiceGenerator\u003e(), // New format\n           _ =\u003e throw new ArgumentException(\"Invalid/Unsupported invoice format\", nameof(invoiceFormat))\n       };\n   }\n   ```\n\n4. Register the new generator in [Program.cs](FactoryPattern.API/Program.cs):\n   ```csharp\n   builder.Services.AddTransient\u003cExcelInvoiceGenerator\u003e();\n   ```\n\n## 📚 Benefits of This Factory Pattern Implementation\n\n1. **Single Responsibility Principle**: Each generator focuses solely on its specific format\n2. **Open/Closed Principle**: Easy to extend without modifying existing code\n3. **Loose Coupling**: Client code depends on abstractions, not concrete implementations\n4. **Testability**: Each component can be easily unit tested\n5. **Maintainability**: Changes to generation logic are isolated to specific classes\n6. **Scalability**: New formats can be added without affecting existing functionality\n\n## 📖 API Documentation\n\nThe project includes comprehensive API documentation powered by NSwag:\n\n1. Start the application\n2. Navigate to `http://localhost:5143/swagger` to access the Swagger UI\n3. Explore and test all available endpoints\n\n## 🤝 Contributing\n\nContributions are welcome! Follow these steps:\n1. Fork the repository.\n2. Create a feature branch: `git checkout -b feature-name`.\n3. Commit your changes: `git commit -m \"Add feature\"`.\n4. Push to the branch: `git push origin feature-name`.\n5. Open a pull request.\n\n## 📄 License\n\nThis project is licensed under the MIT License. See the `LICENSE` file for more details.\n\n## 🙏 Acknowledgements\n\n- [QuestPDF](https://www.questpdf.com/) - For excellent PDF generation capabilities\n- [NSwag](https://github.com/RicoSuter/NSwag) - For API documentation generation\n- [Factory Design Pattern](https://refactoring.guru/design-patterns/factory-method) - For the pattern inspiration\n\n---\n\nHappy coding! 🚀\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmreshboboyev%2Ffactory-pattern","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmreshboboyev%2Ffactory-pattern","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmreshboboyev%2Ffactory-pattern/lists"}