<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/generic-repositories-in-net-wfbgxxeub" -->

---
title: Generic Repositories in .NET | daily.dev
description: Generic repositories reduce duplication by centralizing CRUD operations behind a shared interface, but pure generic repositories are criticized for mirroring...
canonical: https://daily.dev/posts/generic-repositories-in-net-wfbgxxeub
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Generic Repositories in .NET | daily.dev
og:description: Generic repositories reduce duplication by centralizing CRUD operations behind a shared interface, but pure generic repositories are criticized for mirroring...
og:url: https://daily.dev/posts/generic-repositories-in-net-wfbgxxeub
og:image: https://api.daily.dev/og/posts/WFBgXXEuB.png
og:image:alt: Generic Repositories in .NET
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Generic Repositories in .NET

**[NikolaTech](https://daily.dev/sources/nikolatech)** · 4 min read · 0 upvotes · 0 comments

## Summary

Generic repositories reduce duplication by centralizing CRUD operations behind a shared interface, but pure generic repositories are criticized for mirroring DbSet<T> and failing to accommodate entity-specific queries. A hybrid approach is proposed: an abstract BaseRepository handles shared Add/Update/Remove/GetAll logic, while entity-specific interfaces (like IProductRepository) declare both shared and custom methods such as ExistsAsync. Concrete repositories inherit the base class and implement custom behavior, with persistence committed separately through a Unit of Work. Code examples cover the interface, base class, concrete implementation, DI registration, and a command handler consuming the specific interface.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://nikolatech.net/blogs/generic-repositories-in-dotnet>

## Questions this post answers

### Why is a generic repository pattern considered an anti-pattern in .NET?

A pure generic repository is criticized because real applications need custom queries, existence checks, filtered reads, and entity-specific behavior beyond basic CRUD. Once that happens, the generic interface either becomes a dumping ground or forces casting and awkward extension points. It also often ends up mirroring EF Core's DbSet<T> directly, adding ceremony without real value.

_Developers weighing repository designs can compare trade-offs like this on daily.dev before committing to an architecture._

### How can I combine a generic base repository with entity-specific repository interfaces in EF Core?

Create an abstract BaseRepository<TEntity> that wraps shared EF Core operations like Add, Update, Remove, and GetAllAsync using DbContext.Set<TEntity>(). Then define a specific interface per entity, such as IProductRepository, declaring both shared and custom methods like ExistsAsync. A concrete repository inherits the base class and implements the entity-specific interface, while application code depends only on the specific interface, not the base class.

_Developers structuring data access layers can save patterns like this hybrid repository design on daily.dev._

## Similar posts on daily.dev

- [Specification vs Repository vs Query Object in .NET](https://daily.dev/posts/specification-vs-repository-vs-query-object-in-net-hchxk0naa) · We Are .NET · 14 upvotes · 1 comments
- [Abstractions That Heal, Abstractions That Harm](https://daily.dev/posts/abstractions-that-heal-abstractions-that-harm-byjb3ozq1) · We Are .NET · 58 upvotes · 3 comments
- [Creating a Production-Ready CRUD Application in ASP.NET Core](https://daily.dev/posts/creating-a-production-ready-crud-application-in-asp-net-core-1mfpkrepl) · Telerik · 0 upvotes · 0 comments

---

Tags: [#architecture](https://daily.dev/tags/architecture), [#.net](https://daily.dev/tags/.net), [#c#](https://daily.dev/tags/c#)

[View this post on daily.dev](https://daily.dev/posts/generic-repositories-in-net-wfbgxxeub)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Generic Repositories in .NET","url":"https://daily.dev/posts/generic-repositories-in-net-wfbgxxeub","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/generic-repositories-in-net-wfbgxxeub"},"datePublished":"2026-10-04T13:05:58.282Z","dateModified":"2026-10-04T13:17:15.818Z","description":"Generic repositories reduce duplication by centralizing CRUD operations behind a shared interface, but pure generic repositories are criticized for mirroring...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/b68fe6cd835d776636d46c78637dffb7?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/b68fe6cd835d776636d46c78637dffb7?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"NikolaTech","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"NikolaTech","logo":"https://media.daily.dev/image/upload/s--1h2fO6FL--/f_auto,q_auto/v1791119050/logos/nikolatech?_a=BAMAMicg0","url":"https://daily.dev/sources/nikolatech"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/generic-repositories-in-net-wfbgxxeub","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"architecture,.net,c#","timeRequired":"PT4M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"NikolaTech","item":"https://daily.dev/sources/nikolatech"},{"@type":"ListItem","position":3,"name":"Generic Repositories in .NET"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/generic-repositories-in-net-wfbgxxeub#faq","mainEntity":[{"@type":"Question","name":"Why is a generic repository pattern considered an anti-pattern in .NET?","acceptedAnswer":{"@type":"Answer","text":"A pure generic repository is criticized because real applications need custom queries, existence checks, filtered reads, and entity-specific behavior beyond basic CRUD. Once that happens, the generic interface either becomes a dumping ground or forces casting and awkward extension points. It also often ends up mirroring EF Core's DbSet<T> directly, adding ceremony without real value. Developers weighing repository designs can compare trade-offs like this on daily.dev before committing to an architecture."}},{"@type":"Question","name":"How can I combine a generic base repository with entity-specific repository interfaces in EF Core?","acceptedAnswer":{"@type":"Answer","text":"Create an abstract BaseRepository<TEntity> that wraps shared EF Core operations like Add, Update, Remove, and GetAllAsync using DbContext.Set<TEntity>(). Then define a specific interface per entity, such as IProductRepository, declaring both shared and custom methods like ExistsAsync. A concrete repository inherits the base class and implements the entity-specific interface, while application code depends only on the specific interface, not the base class. Developers structuring data access layers can save patterns like this hybrid repository design on daily.dev."}}]}
```

