2022 Developer Survey is open! Take survey.

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
1 vote
1 answer
38 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 ...
user avatar
0 votes
1 answer
133 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 ...
user avatar
1 vote
2 answers
125 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 ...
user avatar
  • 119
0 votes
1 answer
112 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 ...
user avatar
  • 19
2 votes
1 answer
97 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 ...
user avatar
  • 131
1 vote
2 answers
1k 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 { ...
user avatar
-1 votes
3 answers
315 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 ...
user avatar
0 votes
0 answers
37 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 ...
user avatar
0 votes
1 answer
490 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 ...
user avatar
0 votes
1 answer
109 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 ...
user avatar
  • 786
2 votes
1 answer
96 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; ...
user avatar
  • 23
1 vote
3 answers
497 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 ...
user avatar
  • 23
0 votes
0 answers
24 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 ...
user avatar
  • 267
3 votes
1 answer
367 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 ...
user avatar
2 votes
3 answers
197 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 (...
user avatar
1 vote
1 answer
205 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 ...
user avatar
-2 votes
1 answer
240 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(...
user avatar
0 votes
1 answer
117 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 ...
user avatar
1 vote
2 answers
2k 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 ...
user avatar
1 vote
1 answer
46 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 ...
user avatar
  • 21
2 votes
2 answers
1k views

Data Repository and Complex Queries (DTO)

Following the classic 3 layer architecture domain Model (a list of entities live there and has no dependencies) DAL layer - My Repositories lives there with DBContext implementation (Ado.net) Dal ...
user avatar
0 votes
1 answer
305 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 ...
user avatar
1 vote
1 answer
2k 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 ...
user avatar
-4 votes
1 answer
81 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 ...
user avatar
1 vote
2 answers
851 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 ...
user avatar
  • 831
1 vote
1 answer
416 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 ...
user avatar
1 vote
2 answers
559 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 ...
user avatar
  • 345
-1 votes
2 answers
1k 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 ...
user avatar
  • 121
6 votes
4 answers
1k 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 ...
user avatar
  • 119
2 votes
2 answers
374 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; }...
user avatar
-1 votes
3 answers
112 views

When adding a ListFooForBar method, should it go into the FooRepository or BarRepository?

I have a requirement to list country codes (e.g. CA, US) by username. A single user may have zero, one or more countries and a single username. A country has a single country code. I have a ...
user avatar
  • 363
0 votes
0 answers
63 views

Repository Pattern without OR Mapper - Accessing of Attributes

I have a aggregate root called "Billing Document" which has some additional entities as attributes ("Billing lines"). I want to persist these objects together into my database. I read about the ...
user avatar
3 votes
2 answers
5k views

Is unit of work pattern really needed with repository pattern

I am trying to use EF6 with my project. I just watched Repository Pattern with C# and Entity Framework, Done Right | Mosh video. I understand the necessity of Repositories but I still don't understand ...
user avatar
  • 223
0 votes
1 answer
5k views

Is it okay to have one Service with two different Repositories in Spring Boot MVC?

I have a backend Spring Boot API that should have one(?) endpoint that returns some statistics to display in a frontend. These statistics are calculated from data that comes from two different ...
user avatar
  • 109
1 vote
0 answers
161 views

Changing entities in Clean Architecture

I'm modeling the "Domain" Layer of "Clean Architecture" for an application that gets its data from an XML file when starts. The XML file looks like: <?xml version="1.0" encoding="UTF-8" ?> <...
user avatar
3 votes
2 answers
177 views

Should entities have nullable id because they're autoganerated by the database?

Suppose I have a domain entity representing a person. (Examples in TypeScript) class Person { constructor(public name: string) {} } Now, because other parts of the domain will need to reference ...
user avatar
  • 147
-4 votes
3 answers
915 views

Why local database should be the only source of truth for mobile application?

Being mobile developer for quite some time (ios/android) I've learnt that local database is very rarely needed. Mobile application are mobile by definition, they usually serve only as clients to ...
user avatar
-2 votes
1 answer
173 views

Is it acceptable to ditch the Repository pattern in a layered architecture?

My app is using this kind of layered architecture: Controller > Service > Repository > Data Mapper > Persistence Often I notice that my service methods are just directly calling ...
user avatar
  • 313
2 votes
1 answer
4k views

Clean architecture and Repository pattern

I'm working in a new project and I'm trying to use the Clean Architecture approach with Repository pattern. I'm using .net core 3, C#, Automapper, MediatR and Dapper. I have these layers: Domain (in ...
user avatar
6 votes
2 answers
4k views

Avoiding Repository pattern - implementing Onion Architecture with DbContext only

I am trying to follow the Onion Architecture to design my application where I have the following layers - Domain Layer: is the inner-most layer and defines repository interfaces Infrastructure ...
user avatar
  • 183
7 votes
1 answer
807 views

How to prevent concurrency problems when using the repository pattern?

Considering that: when using the repository pattern you deal with entities - those are the atomic units you persist (regardless of Hibernate or "manually") when changing an entity you save it as a ...
user avatar
1 vote
1 answer
147 views

Do authorization checks belong in the controller or the repository/persistor

I have a Laravel project where the controllers (all derived from one of two base controllers) use repository and persistor classes to interface with Eloquent models. Authorization logic is implemented ...
user avatar
  • 155
3 votes
1 answer
207 views

Should I use Repositories or wrap that logic in an additional service layer in my Controllers

I am building a Loopback4 app just for learning; I have a scenario where I have to check for a couple of things before sending that request to the database, so my entry point is my Controllers Method, ...
user avatar
3 votes
3 answers
2k views

DataAccess Layer coupling with Domain Layer

We have an issue with how the implementation of the Data Access layer (EF6 Includes more specifically), influences the behavior of our Domain layer. A theoretical example to illustrate: Application ...
user avatar
  • 133
3 votes
1 answer
1k views

Is it acceptable to invoke business logic inside the repository layer?

I'm learning DDD and I'm wondering if it's ok to invoke domain model logic from inside the repository layer? I don't mean that the business logic exists as part of the repository, merely that the ...
user avatar
0 votes
1 answer
95 views

How to access parent relationship in repository pattern

I have two models Permission and Role, now in roles/create, I need to show all the available permissions to allow admin to select the permission and create a role, now should I import both ...
user avatar
27 votes
5 answers
14k views

Which layer do DDD Repositories belong to?

In his DDD book Evans promotes the idea of layered architecture, and in particular that the business logic should be confined to domain layer and separated from UI/persistence/other concerns. He also ...
user avatar
  • 1,099
0 votes
1 answer
88 views

Questions about Direct access to data source from Services

Background: I'm trying to separate my concerns in the application architecture the best possible way. In a nutshell: The requests are parsed and go to an Action Action decides which service(s) to ...
user avatar
-1 votes
1 answer
2k views

Update Entity for Repository Pattern and UOW Pattern C#

In one mock solution, I have created 3 mock projects to implement layered architecture design mainly the - Presentation Layer (Web) - Domain Model Layer - Infrastructure Layer. I haven't yet to add ...
user avatar
  • 299
2 votes
1 answer
197 views

Mercurial topology in three stage implementation

A few years ago, now, we had a chap working with us who introduced the following topology for Mercurial... The main repository server obviously holds the primary repositories, as you'd expect, but ...
user avatar
  • 201