Questions tagged [repository-pattern]

Pattern that aims to manage a set of persistent objects or a database by providing an interface that emulates a collection.

Filter by
Sorted by
Tagged with
2 votes
1 answer
74 views

What is the correct way to configure a testing mode on a class?

I have a repository which reads and writes to Firestore, and some tests to make sure data is sent and comes back in the correct way. In order to test this I added a protected function which returns ...
Adam's user avatar
  • 272
3 votes
1 answer
154 views

How to structure repositories for a small number of entities?

I am working on a project implemented in DDD style, and I use Repository architecture pattern to persist domain changes. I have multiple roles in domain layer, and that's what raises my question - how ...
lubitelpospat's user avatar
0 votes
2 answers
132 views

Repository concerns

We have a layered application with (basically): WebAPI, App Services, Domain and Repository layers. This fits for most situations, but now we face a slightly different challenge on where we need to ...
zameb's user avatar
  • 121
0 votes
4 answers
154 views

How to Access the Private State of an Entity in the Save Method of its Repository

Consider the domain entity, Order, which can be persisted by the OrderRepository. Orders maintain state that is stored in the database. However, it does not expose all of it directly. That is, parts ...
STHA's user avatar
  • 39
2 votes
9 answers
3k views

Is it an anti-pattern to use interface for entity?

I read an article about that using an interface for an entity is an anti-pattern for these reasons: Your interface signature is identical to your class. There’s only one implementation of your ...
Mercury's user avatar
  • 53
2 votes
1 answer
184 views

How to properly use Data Transfer Objects

I feel something is wrong with my approach handling MVP and the Repository Pattern. I'm making an album winform app just to practice MVP, crud and the Repos. Pattern. First some code. The model: using ...
Valmont's user avatar
  • 173
4 votes
2 answers
467 views

Should I save my entire domain object or update individual properties?

Scenario: An application is going to perform operations on an entity. That means retrieving it from storage, possibly making modifications, and then persisting those changes back to storage. I'm ...
Scott Hannen's user avatar
  • 1,014
1 vote
3 answers
1k views

How to implement Repository if only part of Entity properties are needed?

From many articles and answers on DDD Repository pattern, I got the feeling that a Repository should only CURD an Entity (Aggregate Root) as a whole. Following this convention, we always need to query ...
zwcloud's user avatar
  • 111
2 votes
1 answer
1k views

Build a Rust project using Clean architecture and DB transactions in the same DDD bounded context

This is just an example of an (still incomplete) real-world project written in Rust using a clean architecture: https://github.com/frederikhors/rust-clean-architecture-with-db-transactions. Goals My ...
Fred Hors's user avatar
  • 139
1 vote
3 answers
663 views

Using Repository Pattern with .NET Entity Framework with a single Get method with optional parameters for each table include

We have a very messy data repository component, with dozens of methods to interface a DbContext (entire database) in Entity Framework. It was (and is) coded in a way that adds a new repo method for ...
Veverke's user avatar
  • 423
1 vote
1 answer
1k views

Best practices repository and service layer

I have read many articles about repository pattern and service layer but I have still some doubts in certain arguments: Repository should return only aggregates and I should have repositories only ...
Alfons Deda's user avatar
0 votes
1 answer
1k views

Generic Repositories with different IDbConnections

I have two different connection strings for two different databases. My first database has 2 relational tables: -First table has some default fields,among which average on UI, and some additional ...
Alfons Deda's user avatar
0 votes
2 answers
520 views

What if a Repository needs to apply Business Logic to load an Aggregate?

I have an aggregate User and the user has a Score. The Score of a user is calculated by queriying a bunch of different tables and running through (often very large) result sets applying some business ...
Mats's user avatar
  • 163
0 votes
0 answers
398 views

Where/how does the conversion of entity objects to data transfer objects take place in Clean Architecture?

Prolog: I have a domain-layer which contains some entity-classes like Customer. I have a application-layer which contains some data transfer object classes like CustomerDto. My Problem: At a presenter ...
Cit's user avatar
  • 21
3 votes
1 answer
382 views

Should repositories return self persisting entities?

In domain driven design A repository is a collection like "interface" that hides data source access. It furnish add, remove and retrieval method just like a collection would. It does it ...
Ced's user avatar
  • 315
4 votes
3 answers
732 views

Are repositories async?

Repositories in ddd should give the illusion of an in memory collection. and A Repository is essentially a facade for persistence that uses Collection style semantics (Add, Update, Remove) to supply ...
Ced's user avatar
  • 315
0 votes
2 answers
358 views

How to model transactions in a client-side functional DDD?

I'm new to DDD and I would like to clarify some concepts. I'm thinking about DDD in the client-side. The first one is regarding transactions: My understanding is that transactions are a responsibility ...
João Otero's user avatar
4 votes
2 answers
1k views

How to manage the entity which have collection of child entities in DDD?

A play arena contain a list of Machines and Amenities playArena : guid : GUID name : string location: Location owner: string amenities: Amenities playing_machines: PlayingMachines ...
Mr X's user avatar
  • 149
0 votes
1 answer
680 views

Clean Architecture: How to decouple the Repository from a CommandHandler?

We are just starting with event driven (and clean) architecture. So far we have two main entrypoints, a consumer (reader from a Redis Stream / Kafka Topic), and an API. As this is almost a modular ...
lowercase00's user avatar
1 vote
3 answers
801 views

Design pattern for persistent data storage - load and save arbitrary file, database, api etc

I have the following problem - I write the code for object data manager, and one of requirements is being able to save/load data into some persistent data storage. I want to make it as the following: ...
Ch3shire's user avatar
  • 121
2 votes
1 answer
1k views

How to integrate Androidx Paging-3 in Clean Architecture?

This blog on "Clean Architecture" describes how to build a modular Android application along with using Clean Architecture. In that example project, the author places the business logic in a ...
Sourav Kannantha B's user avatar
0 votes
1 answer
610 views

How to conform two repositories that work on the same entity but have different methods?

I have to implement 2 use cases, the first one is going to create a Company profile from its document number, so inside the use case, it reaches out to the third party API that contains information ...
Thiago Dias's user avatar
1 vote
2 answers
2k views

Difference between Strategy pattern and Repository pattern

I found the following definition of Repository Pattern: Repositories are classes or components that encapsulate the logic required to access data sources. They centralize common data access ...
DFSFOT's user avatar
  • 119
0 votes
1 answer
279 views

In a layered architecture with exchangable data providers, how to deal with provider-specific implementation details?

Assume an application architecture with three layers (presentation, domain, data access - though presentation is irrelevant to this question) that follows dependency inversion: The domain layer ...
hingst's user avatar
  • 29
2 votes
1 answer
598 views

Should integration tests of a repository pattern use low-level ORM calls

Problem summary: In an application with wrapper methods over SQLAlchemy add() and query() methods, can integration tests that use the add() method wrapper use the query() method wrapper to validate ...
Ash's user avatar
  • 131
8 votes
2 answers
13k views

To which Clean Architecture layer should repositories implementations belong?

It's very common to see this use of repository in projects using clean architecture: interface Hero { } interface HeroRepository { findById(id: number): Hero; } class FetchHeroUseCase { ...
Vitor Figueredo Marques's user avatar
-1 votes
3 answers
1k views

Is it a bad idea to save the database in middleware?

So I've implemented the repository pattern in a lot of projects, but there seems to be a bit of a discussion on what is right with this pattern. Previously, I've always added Update or Create methods ...
Roy Berris's user avatar
0 votes
0 answers
39 views

Retrieving related information using the repository pattern [duplicate]

I'm currently working on refactoring a project to use the repository pattern, but I'm currently struggling with how related information should be retrieved. Let's say I have a Hotels and Rooms. I have ...
Matthew Weeks's user avatar
0 votes
1 answer
2k views

Encapsulation of External API in Infrastructure Layer AS Persistence

My question is about DDD, the Infrastructure layer, it's relation to the Domain, and specifically how we can take advantage of the ability to "swap out" one persistence implementation for ...
apriestley's user avatar
0 votes
2 answers
939 views

Obtaining application generated ID from repository or from entity constructor?

In the Book "Implementing Domain-Driven Design" the author suggests to implement a repository method to provide the next application-generated (not database-generated) ID. Like so: class ...
deamon's user avatar
  • 876
3 votes
1 answer
417 views

Builder that creates a repository for a specific entity - is this an established pattern?

Suppose I have the following entities: class Employee { public string Id { get; set; } public ICollection<EmployeeBadge> Badges { get; set; } } class Badge { public string Id { get; ...
Sara E's user avatar
  • 33
1 vote
3 answers
1k views

Some thoughts on the Repository pattern

Until this moment, I have seen a lot of variations and combinations of the Repository pattern, implementations that simply queried the required information, some used something like a mapper, some ...
qUneT's user avatar
  • 53
0 votes
0 answers
74 views

Repository Pattern to support Bounded Context

I am building a REST Api from scratch so i am overthinking and revisiting various approaches and best practices. I have a Materials repository that serve all the sub-domains of our logic. Also i have ...
e4rthdog's user avatar
  • 267
3 votes
1 answer
802 views

CRUD is too simplistic for my usecases, how would you handle the repository pattern when using MediatR and EF Core?

I have a .Net 5 Web API project and use MediatR to encapsulate my business logic into commands and queries since I don't like to have a single CRUD service handling everything related to a specific ...
Olaf Svenson's user avatar
2 votes
3 answers
488 views

domain model logic behavior (ddd)

How domain model capture business logic / domain logic since i cannot access repository? I see many posts saying that domain model = business objects But Business objects live in application layer (...
Stelios's user avatar
  • 205
1 vote
1 answer
424 views

C# Design for database queries and commands

Currently I'm working on a project that will interact with a database. Based on my research, I would like to develop a repository class which responsability is to write/extract entities to/from a ...
Victor Gazzinelli's user avatar
-2 votes
1 answer
896 views

ViewModels and DTO mixed with repository pattern

Some parts in our project's codebase implement the repository pattern in a different way from what we usually do Here's the example public class Repository : IRepository { public Repository(...
Józef Podlecki's user avatar
1 vote
1 answer
331 views

Managing Documentation / Source Control for a Full-Stack Application Across Multiple Repos

TL;DR I have a moderately sized/complexity web application (Angular 11) in one repo and a standalone REST API (.NET Core 3 / C#) in another repo, and am trying to figure out the most efficient way to ...
Kurtis Jungersen's user avatar
2 votes
2 answers
7k views

Error handling for repository: exceptions or wrapping return value?

The question is about a desktop application I'm creating in C# and WPF. As very common I'm using the repository pattern in my Data Access Layer for my CRUD operations. All data comes from the ...
user2190492's user avatar
1 vote
1 answer
110 views

Deisgn Pattern: How to map UI requests to Controllers to Services?

I'm learning about writing WebApi design patterns. I am trying to create a simple CRUD web app with ReactJS UI and C# .NET CORE webapi with sql backend. Articles show that specific Repositories are a ...
klau's user avatar
  • 21
6 votes
2 answers
4k views

Data Repository and Complex Queries (DTO)

Following the classic 3 layer architecture domain Model (a list of domain models live there and has no dependencies) DAL layer - My Repositories lives there with DBContext implementation (Ado.net) ...
Stelios's user avatar
  • 205
0 votes
1 answer
2k views

Best practice for pulling bulk data from APIs and storing in database

I have written a small application using ASP.NET Core to create and manage collections of cards for a collectable card game. I currently have a version that successfully downloads bulk card data via ...
DogoPilot's user avatar
3 votes
1 answer
6k views

Repository Pattern with Services Layer - Good Practice?

This is my first time I am using repository pattern and applying a layered architecture in a project. I have followed the article found here. The complete code found on the article can also be found ...
Subliminal Hash's user avatar
-4 votes
1 answer
160 views

Changing databases in general repository methods when using Dapper [closed]

I'm developing a multi-database application. There is one admin database and many customer databases which are identical in structure. I also have a generic RepositoryBase which looks like the ...
Mitulát báti's user avatar
1 vote
2 answers
2k views

repository pattern, using the domain object as data access object

I'm very puzzled by a specific part of the repository pattern that seems simple but turn out to be tricky. I took this great explanation of this topic by Mosh Hamedani; it's a C# implementation of ...
AgostinoX's user avatar
  • 841
1 vote
1 answer
1k views

Repository layer with multiple data sources

I am implementing a repository layer in my mobile application. I would like the repository layer to complete to abstract the details about where the data it coming from/ or how we retrieve it from the ...
Libin Joseph's user avatar
2 votes
2 answers
2k views

Repository pattern - using information from other repositories

I am trying to understand what is the proper approach when the objects generated from a Repository have a reference to objects which are responsible for another Repository. Let's say I have terminals ...
djvuk's user avatar
  • 365
-1 votes
2 answers
2k views

How to use Dependency Injection on repositories in Generic Repository Pattern with base class inheritance

How to dependency inject repositories that inherit an abstract class (that inherits another abstract class) which implements the interface? I will give you a simplified version of my current ...
Nikolai's user avatar
  • 131
9 votes
4 answers
3k views

Should access control be implemented in controller or repository layer?

I've got a project with an HTTP API which returns data from a database. The layers it goes through to get to the API look like this: DB -> Repository -> Controller I'm looking to restrict the ...
Joundill's user avatar
  • 149
2 votes
3 answers
876 views

Database Model Classes in TypeScript

I'm using Knex.js with TypeScript for database access. Table uid (UUID, auto-generated by Postgres) name (varchar) Model interface User { uid: string | null; name: string; }...
John Mark Gabriel Caguicla's user avatar