repository-patterns

Implement repository and Unit of Work patterns for .NET with Entity Framework Core.

4|1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill repository-patterns-faysilalshareef
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: repository-patterns
Source: https://github.com/FaysilAlshareef/dotnet-ai-kit/tree/main/skills/data/repository-patterns
Command: npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill repository-patterns-faysilalshareef

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Centralizes data access to prevent leaky abstractions, reduce duplicated EF Core usage, and ensure transactional consistency across aggregate operations so handlers and services remain domain-focused and testable.

Core Features & Use Cases

  • Repository per aggregate root: Encourages modeling repositories around aggregate roots rather than individual entities.
  • Unit of Work coordination: Shows how DbContext can act as the UoW and how to expose SaveChanges through an interface.
  • Generic + specialized repositories: Provides patterns for open-generic CRUD and aggregate-specific queries, including examples with Include, AsSplitQuery, and ordering.
  • Specification support & DI: Describes integrating Ardalis.Specification and registering repositories and UoW with dependency injection for production use.
  • Use Case: Implementing an Order aggregate with a specialized IOrderRepository that returns domain entities and supports complex query scenarios like pagination and projections.

Quick Start

Use this skill to implement repository interfaces, a Unit of Work, generic and specialized EF Core repository implementations, and register them with DI in your .NET project.

Frequently Asked Questions about repository-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement the repository pattern with EF Core for aggregate roots?

To implement the repository pattern with EF Core, model repositories around aggregate roots rather than individual entities, providing interfaces for generic and specialized repositories that return domain entities without exposing IQueryable. This centralizes data access and prevents leaky abstractions.

What is the Unit of Work pattern in .NET and when do I need it?

The Unit of Work pattern in .NET coordinates transactional consistency across aggregate operations by exposing SaveChanges through an interface. You need it to ensure transactional consistency across aggregate operations so handlers and services remain domain-focused and testable.

How do I register repositories and Unit of Work with dependency injection in .NET?

Register repositories and Unit of Work with dependency injection in .NET by configuring interfaces for generic and specialized repositories alongside the UoW interface. This DI registration supports production use and ensures consistent domain-centric data access throughout your application.

Can I use the specification pattern with EF Core to handle complex queries?

Yes, you can use the specification pattern with EF Core by integrating Ardalis.Specification. This supports specification-driven queries for complex scenarios like pagination and projections, allowing specialized repositories to handle complex query requirements without exposing IQueryable.

Why should I use a repository per aggregate root instead of per entity?

Using a repository per aggregate root instead of per entity centralizes data access to prevent leaky abstractions and reduces duplicated EF Core usage. This approach ensures transactional consistency across aggregate operations so that handlers and services remain domain-focused.

Does this repository pattern approach support CQRS read models and split queries?

Yes, this repository pattern approach supports CQRS read models and split queries. It provides patterns for aggregate-specific queries, including examples with Include, AsSplitQuery, and ordering, enabling specialized repositories to handle complex query scenarios like pagination and projections.