Skip to content

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.

Notifications You must be signed in to change notification settings

MrEshboboyev/FactoryPattern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Factory Pattern for Invoice Generation

This project demonstrates a .NET implementation of the Factory Pattern to generate invoices in multiple file formats (PDF, TXT, and CSV). It uses QuestPDF to create professional-grade PDF documents and follows the Repository Pattern to ensure clean and maintainable data access.

Features

  • Factory Pattern: Simplifies the creation of invoices in various file formats.
  • Invoice Generation: Supports generating invoices as PDF, TXT, and CSV files.
  • QuestPDF Integration: Produces high-quality and customizable PDF invoices.
  • Repository Pattern: Provides a structured and maintainable data access layer.
  • Extensible Design: Easily add support for new file formats or invoice types.

Prerequisites

Installation

  1. Clone the repository:
    git clone https://github.com/MrEshboboyev/FactoryPattern.git
  2. Navigate to the project directory:
    cd FactoryPattern
  3. Restore dependencies:
    dotnet restore

Usage

Invoice Generation

The application uses the Factory Pattern to generate invoices in different formats. Below is an example of how to generate invoices in endpoint:

var generator = invoiceGeneratorFactory.CreateInvoiceGenerator(format);
var invoiceData = generator.GenerateInvoice(id);
var contentType = generator.GetContentType();

var fileName = $"Invoice_{id}.{format.ToString().ToLower()}";
    
return Results.File(invoiceData, contentType, fileName);

Adding New Formats

To support a new file format:

  1. Create a new class implementing the IInvoiceGenerator interface.
  2. Add the new file type to the InvoiceFormat enum.
  3. Update the InvoiceGeneratorFactory to include the new type.

Example:

public class ExcelInvoiceGenerator : IInvoiceGenerator
{
    public byte[] GenerateInvoice(Guid invoiceId)
    {
        // Logic to generate an Excel invoice
    }
}

Supported File Formats

  • PDF: Generated using QuestPDF.
  • CSV: Comma-separated structured invoice data.
  • TXT: Simple text-based invoice output.

Contributing

Contributions are welcome! Follow these steps:

  1. Fork the repository.
  2. Create a feature branch: git checkout -b feature-name.
  3. Commit your changes: git commit -m "Add feature".
  4. Push to the branch: git push origin feature-name.
  5. Open a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Acknowledgements


Happy coding! 🚀

About

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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages