implementing-repository-pattern

Implements the Repository pattern with Service Layer for data access abstraction in .NET applications.

Updated Nov 22, 2023
One-click install
npx skills add https://github.com/parksanghoon-sys/TestCode --skill implementing-repository-pattern-parksanghoon-sys
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: implementing-repository-pattern
Source: https://github.com/parksanghoon-sys/TestCode/tree/main/src/Modbus/wpf-dev-pack/.agents/skills/implementing-repository-pattern
Command: npx skills add https://github.com/parksanghoon-sys/TestCode --skill implementing-repository-pattern-parksanghoon-sys

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Mixing data access logic directly into ViewModels or business code makes .NET applications hard to test and maintain. This Skill provides a complete guide for separating data access into a Repository layer and business logic into a Service layer, with proper dependency injection wiring. ## Core Features & Use Cases - Repository Layer: Defines interfaces and implementations for CRUD operations (GetAllAsync, GetByIdAsync, AddAsync, UpdateAsync, DeleteAsync) abstracting the data source. - Service Layer: Encapsulates business logic on top of repositories, exposing read-only results to the presentation layer. - DI Registration: Shows registration with GenericHost (AddSingleton) and includes a Prism 9 variant (RegisterSingleton via IContainerRegistry) in PRISM.md. - Use Case: A WPF ViewModel currently calls a database directly; use this Skill to refactor it into App → Service → Repository layers with constructor injection, making the code unit-testable. ## Quick Start Ask the AI to implement a Repository pattern with a Service layer for a User entity in your .NET project, including DI registration.

Frequently Asked Questions about implementing-repository-pattern

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

FAQPage Schema
How do I implement the Repository pattern in .NET?▼

Define an interface like IUserRepository with async CRUD methods, then create a concrete implementation such as UserRepository. Register the pair in the DI container with services.AddSingleton and inject it into a Service class via the constructor.

What is the difference between Repository and Service layer in C#?▼

The Repository layer handles only data access operations against a data source, while the Service layer contains business logic and calls the repository. This separation keeps business rules independent of storage details and improves testability.

How do I register repositories with Prism 9 dependency injection?▼

In Prism 9, override RegisterTypes in your PrismApplication and call containerRegistry.RegisterSingleton<IUserRepository, UserRepository>(). Modules can also register their own repositories inside their RegisterTypes method.

Should I use a generic repository interface in .NET?▼

A generic IRepository<T> with standard CRUD methods reduces duplication when many entities share the same operations. For entities with specialized queries, prefer dedicated interfaces like IUserRepository to keep contracts explicit.

When should I not use the Repository pattern?▼

Avoid it for trivial applications where an ORM like Entity Framework already abstracts data access, since adding another layer only adds indirection. It is most valuable when you need testability, multiple data sources, or complex business logic separation.