DEFC.Util.RepoGen

DEFC.Util.RepoGen is a powerful NuGet tool designed to streamline the implementation of the Repository and Unit of Work design patterns in
.NET applications. By automating the generation of repository classes that interact with stored procedures (SP) in your database, this
tool significantly enhances developer productivity while promoting a clean, maintainable architecture by:
- Mapping stored procedures to repository methods
- Automatically generating CRUD operations for database tables
- Creating DTOs and models to match your data structure
- Optionally generating REST API endpoints for services
- Supporting different architectural patterns (Clean, Layered, Hexagonal, or Custom)
Whether you need to quickly scaffold your backend or integrate stored procedures with modern architecture, RepoGen helps you do it with minimal manual effort.
Quick Links
Documentation
Step-by-step practice sample guide
Step-by-step practice sample with custom model guide
FAQ
ℹ️ About
DEFC.Util.RepoGen is one of DEFC utilities packages. It is a .NET CLI tool and NuGet package that helps developers quickly
generate repositories and Unit of Work classes that map to SQL Server stored procedures (SP). It is designed to
automate repetitive tasks, reduce boilerplate code, and maintain a clean architecture within .NET applications.
This tool empowers development teams to enforce consistent patterns, improve productivity, and accelerate the creation of scalable
applications that interact with databases via stored procedures.
The tool organizes generated code into seven main folders to promote clean architecture and maintainability:
- Repositories – Concrete implementations for data access operations.
- IRepositories – Interfaces defining repository contracts.
- DbContext – Centralized configuration and connection management.
- UnitOfWork – Coordinates transactional operations across repositories.
- Models – Domain entities mapped to database structures.
- DTOs – Data transfer objects for client-facing and API-layer interactions.
- Services – Business logic and application service layer implementations.
🚧 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.
🧪 How You Can Help:
- Try using the tool in a real .NET project
- Report issues or bugs via the GitHub Issues page
- Share suggestions or improvements
- Contribute usage scenarios or sample batch files
🙏 Thank you for supporting the development of DEFC.Util.RepoGen
.
Let’s build something great together!
🎯 Objective
NuGet tool that implements the repository and unit of work patterns by automating the creation of repositories mapped to database stored procedures (SPs). This enhances developer productivity and helps maintain clean architecture in .NET applications.
⚠️ Important: This is a brief README. For full details, please refer to the Documentation (recommended).
🚀 Benefits
- Reduced Boilerplate: Developers don't need to manually create the repository and methods for every stored procedure. The tool can automatically generate them.
- Enforces Clean Architecture: The separation of concerns between database operations (in the repository) and business logic (in the service) is maintained.
- Promotes Maintainability: When working with stored procedures, the tool keeps the codebase more organized and easier to maintain, as the SP logic is encapsulated in the repository.
- Speeds Up Development: Instead of writing repetitive code, developers can focus more on writing business logic by using the generated repositories.
🔌 Supported Technologies
The tool is designed to work seamlessly within modern .NET environments using clean architecture principles.
🗄️ Database Providers
- Microsoft SQL Server (current supported provider)
⚠️ Important on Other Databases
DEFC.Util.RepoGen
does not support PostgreSQL or MySQL because:
- These databases do not provide the same stored procedure metadata needed for automated mapping.
- Their procedural SQL dialects differ significantly from T-SQL (used in SQL Server).
- The tool is tightly coupled to SQL Server’s stored procedure introspection capabilities.
⚠️ Important: For PostgreSQL or MySQL, consider using EF Core’s model- or code-first patterns instead.
⚙️ .NET Versions
🧱 Design Patterns Used
- Repository Pattern – abstracts data access and encapsulates business logic interactions.
- Unit of Work – coordinates the writing out of changes and maintains transactional integrity.
- Command Pattern (CLI-based) – the tool is built around modular command-line operations.
- Separation of Concerns – enforces clean boundaries between infrastructure and domain logic.
💡 Important: The tool helps teams enforce these patterns consistently across the codebase, especially when working with stored procedures.
🖥️ Recommended Execution Environments
You can run the tool using any of the following:
- Developer PowerShell for Visual Studio (recommended) — provides better visualization and output formatting.
- .NET CLI from terminal or command prompt (recommended) — provides better visualization and output formatting.
- Package Manager Console in Visual Studio.
💡 Important: For best experience and readability, use Developer PowerShell or .NET CLI.
🛠️ Prerequisites
- Install the following NuGet packages:
Microsoft.Data.SqlClient
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore
🏁 Usage Guide
📁 Initialization
- Initialize the RepoGen tool
dotnet tool run RepoGen initial
🔧 Configuration
Customize the RepoGen.json
file with your specific data and save the changes View configuration options →.
🗂️ Structure Setup
- Generate the repository pattern folder structure:
dotnet tool run RepoGen structure set
🧪 Testing
- To confirm if the connection string in
RepoGen.json
is working:
dotnet tool run RepoGen test db-connection
- Test the structure model:
dotnet tool run RepoGen structure test
🧱 Repository and Unit of Work Generation
- Add a Unit of Work class (if not already added):
dotnet tool run RepoGen add --uow
- Add a generic CRUD repository:
dotnet tool run RepoGen add --crud
- Add a new repository with unit of work (if not exists):
dotnet tool run RepoGen add --repo <YourRepoName>
🔁 Stored Procedure Mapping
- Map a stored procedure to a repository:
dotnet tool run RepoGen map --sp <YourStoredProcedureName> --repo <YourRepoName>
- Map a stored procedure to a repository with endpoint generating:
dotnet tool run RepoGen map --sp <YourStoredProcedureName> --repo <YourRepoName> --controller <ControllerName> --endpoint <EndpointName> --<Method>
- Remap a stored procedure to a repository:
dotnet tool run RepoGen re-map --sp <YourStoredProcedureName> --repo <YourRepoName>
- Remap a stored procedure to a repository with endpoint generating:
dotnet tool run RepoGen re-map --sp <YourStoredProcedureName> --repo <YourRepoName> --controller <ControllerName> --endpoint <EndpointName> --<Method>
- Remove a mapped stored procedure:
dotnet tool run RepoGen remove --sp <YourStoredProcedureName> --repo <YourRepoName>
🧬 CRUD from Table
- Generate CRUD operations for a table:
dotnet tool run RepoGen crud --tbl <YourTableName> --service <YourServiceName>
- Generate CRUD operations for a table with endpoint generator:
dotnet tool run RepoGen crud --tbl <YourTableName> --service <YourServiceName> --controller <YourControllerName>
📄 Batch Operations
dotnet tool run RepoGen add --batch <YourBatchFileWithoutExtension>
- Run a batch of commands from a JSON file:
dotnet tool run RepoGen batch --file <YourBatchFileWithoutExtension>
♻️ Reset
- Reset exists Unit of Work class:
dotnet tool run RepoGen reset --uow
- Reset exists generic CRUD repository:
dotnet tool run RepoGen reset --crud
Note: This is a brief README. For full details, please refer to the Documentation (recommended).
📝 License
This project is licensed under the Elastic License 2.0.
✔️ You are permitted to:
- Use the software for any purpose, including commercial use.
- Run the software as part of your service offering.
❌ You are not permitted to:
- Modify the software.
- Redistribute the software, in whole or in part, or as part of another software product.
- Remove any attribution or claim the software as your own.
- Use the software to build or offer a competing service.
By using this software, you agree to the Elastic License 2.0 →.
👩💻 Author
Amina El-Sheikh
🔗 GitHub • LinkedIn
🐞 Issues & Feedback
Found a bug or want to contribute?
📬 Open an issue
📎 Related Packages
🙏 Thank you for supporting the development of DEFC.Util.RepoGen. Let’s build clean, maintainable .NET applications together!