DEV Community

Amina Elsheikh
Amina Elsheikh

Posted on

πŸ› οΈ Automate Repository Generation in .NET with RepoGen

DEFC.Util.RepoGen

If you’ve ever built a .NET application that uses stored procedures, you’ve probably written a lot of repetitive repository code. While clean architecture and the repository pattern are great for maintainability, they come with a cost β€” boilerplate.

That’s why I built RepoGen β€” a NuGet CLI tool that helps .NET developers automatically generate repository classes, structure folders, and map stored procedures with just a few commands.

🧩 What is RepoGen?

DEFC.Util.RepoGen is a .NET CLI and NuGet tool that automates the implementation of the Repository
and Unit of Work patterns using SQL Server stored procedures. It simplifies the generation of clean,
scalable, and maintainable architecture in .NET applications, while promoting strong separation of concerns.

🚧 Beta Version Notice
πŸ”¬ This is a Beta Release
DEFC.Util.RepoGen is currently in beta and under active testing. While it is functional and ready for
practical use, we are still refining and improving the tool based on user feedback.

We invite developers and teams to test the tool in real-world scenarios and help us identify bugs, edge cases, or areas for improvement.
Your feedback is valuable and will directly contribute to shaping the final stable release.

πŸ› οΈ Key Features

  • βœ… Automatic Repository Generation – Generates repository classes mapped to SQL Server stored procedures.
  • βœ… Unit of Work Integration – Creates a UnitOfWork class to manage transactions across repositories.
  • βœ… Stored Procedure Mapping – Automates method creation inside repositories that correspond to stored procedures.
  • βœ… CRUD Generator – Generates full CRUD (Create, Read, Update, Delete) logic and models for SQL tables.
  • βœ… Clean Architecture Support – Supports multiple folder structures: Clean, Layered, Hexagonal, or Custom.
  • βœ… Batch Command Execution – Run multiple operations from a JSON batch script.
  • βœ… Dynamic DTO & Model Generation – Generates Data Transfer Objects and domain models from stored procedures or tables.
  • βœ… Endpoint Creation – Auto-generates RESTful controller endpoints (e.g., POST, GET, PUT, DELETE) alongside SP and CRUD mappings.
  • βœ… Offline & Secure – Operates fully offline with no external calls or telemetry.

πŸ›  Prerequisites

Install required EF Core dependencies:

dotnet add package Microsoft.EntityFrameworkCore
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet add package Microsoft.Data.SqlClient
Enter fullscreen mode Exit fullscreen mode

πŸ“¦ Installation

Install the NuGet package:

dotnet new tool-manifest
Enter fullscreen mode Exit fullscreen mode
dotnet tool install --local DEFC.Util.RepoGen --version 1.0.0-beta
Enter fullscreen mode Exit fullscreen mode

πŸš€ Quick Start

  • Initialize:
dotnet tool run RepoGen initial
Enter fullscreen mode Exit fullscreen mode

dotnet tool run RepoGen initial

  • Configure RepoGen.json:
{
  "Config": {
    "DBConfig": {
      "SchemaID": "1",
      "DBContextName": "YOUR_DBCONTEXTNAME_HERE",
      "ConnectionString": "Server=SERVER_NAME;Database=DATABASE_NAME;User Id=USER_NAME;Password=PASSWORD;TrustServerCertificate=True"
    },
    "AppConfig": {
      "Namespace": "YOUR_NAMESPACE_HERE",
      "FoldersStructureModel": "MODEL_1",
      "LoggerCode": "101",
      "Suffixes": {
        "Model": "Models", // Suffix for domain or entity classes
        "DTO": "Dtos" // Suffix for data transfer objects 

      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode
  • Generate Folder Structure:
dotnet tool run RepoGen structure set
Enter fullscreen mode Exit fullscreen mode
  • Test DB Connection:
dotnet tool run RepoGen test db-connection
Enter fullscreen mode Exit fullscreen mode
dotnet tool run RepoGen  structure test
Enter fullscreen mode Exit fullscreen mode
  • Generate CRUD for a Table:
dotnet tool run RepoGen crud --tbl <YourTableName> --service <YourServiceName> --controller <YourControllerName>
Enter fullscreen mode Exit fullscreen mode
dotnet tool run RepoGen crud --tbl <YourTableName> --service <YourServiceName>
Enter fullscreen mode Exit fullscreen mode
  • Stored Procedure Mapping

1- Map a stored procedure to a repository:

dotnet tool run RepoGen map --sp <YourStoredProcedureName> --repo <YourRepoName> --controller <ControllerName> --endpoint <EndpointName> --<Method>
Enter fullscreen mode Exit fullscreen mode
dotnet tool run RepoGen map --sp <YourStoredProcedureName> --repo <YourRepoName>
Enter fullscreen mode Exit fullscreen mode

2- Remap a stored procedure to a repository with controller endpoint:

dotnet tool run RepoGen re-map --sp <YourStoredProcedureName> --repo <YourRepoName> --controller <ControllerName> --endpoint <EndpointName> --<Method>
Enter fullscreen mode Exit fullscreen mode

3- Remove a mapped stored procedure:

dotnet tool run RepoGen remove --sp <YourStoredProcedureName> --repo <YourRepoName>
Enter fullscreen mode Exit fullscreen mode

πŸ“ Architecture Support

  • 🧱 MODEL_1: Clean Architecture (default)
  • 🧱 MODEL_2: Layered Architecture
  • 🧱 MODEL_3: Hexagonal (Ports & Adapters)
  • 🧱 MODEL_CUSTOM: Fully configurable layout via custom_model.json

πŸ“š Documentation

Full guides, step-by-step examples, and command references are available in the πŸ“˜ Wiki

πŸ“¦ Try It Yourself

RepoGen is available now as a NuGet package. If you're working on a .NET project and want to save time while keeping your code clean, give RepoGen a try!

You can find RepoGen on NuGet.

You can find RepoGen sample on GitHub.

πŸ“Ž Related Packages

πŸ“„ License

Licensed under the Elastic License 2.0.
See full license details here.

🐞 Issues & Feedback

Found a bug or want to contribute?
πŸ“¬ Open an issue

πŸ“š More About RepoGen

πŸ™ Thank you for supporting the development of DEFC.Util.RepoGen. Let’s build clean, maintainable .NET applications together!

Top comments (0)