47 votes
Accepted

Which layer do DDD Repositories belong to?

Repositories and their placement in the code structure is a matter of intense debate in DDD circles. It is also a matter of preference, and often a decision taken based on the specific abilities of ...
Subhash's user avatar
  • 1,581
40 votes
Accepted

Should Entity Framework 6 not be used with repository pattern?

To get this out of the way, I am a big proponent of Entity Framework, but it does come with some drawbacks that you need to be aware of. I also apologize for the long answer, but this is a very hot ...
Flater's user avatar
  • 48.7k
23 votes
Accepted

How to structure microservices in your repository

No code reuse is usually understood as a selling point for microservices! the microservices can be developed and deployed independently different microservices can use different technologies, in ...
amon's user avatar
  • 134k
22 votes
Accepted

Is unit of work pattern really needed with repository pattern

The Entity Framework DbContext is a unit of work, and its DbSet<T> properties are repositories. That's not to say that you should never roll your own layer on top of them, but you're correct in ...
Flater's user avatar
  • 48.7k
15 votes

Is it a good idea to share repositories across microservices in Spring Boot Application?

I vehemently opposed Vehemence makes others stop listening and limits our perception, hence our capacity to find solutions too. In my experience, we are vehement at defending or opposing ideas we don'...
Laiv's user avatar
  • 14.6k
14 votes
Accepted

Access multiple entities in repository - clean architecture

Your repository doesn't break the "clean architecture", which identifies entities as the core, requires dependency inversion, but doesn't impose to use repositories. But your repository ...
Christophe's user avatar
  • 76.8k
13 votes

Should access control be implemented in controller or repository layer?

Ideally, if you really require a high level of security, the DB itself should not return any data for which the requester does not have the permission. With this idealistic idea in mind, the answer ...
Doc Brown's user avatar
  • 206k
12 votes
Accepted

Repository pattern, call another API that updates a SOR's from service or repository class?

The calls to other APIs should go in the repository layer. The service layer shouldn't care how it gets its data, no matter where that data comes from. The job of a repository isn't communicating ...
Greg Bair's user avatar
  • 345
11 votes

If Repository Pattern is overkill for modern ORMs (EF, nHibernate), what is a better abstraction?

I think you are conflating repositories and generic repositories. A basic repository just interfaces your data store and provides methods to return the data IRepository { List<Data> ...
Ewan's user avatar
  • 74.6k
11 votes

Which layer do DDD Repositories belong to?

Which layer Repositories belong: the Domain Layer, Persistence Layer or something in the middle? If you believe in dependency inversion*, then repositories are contracts defined by the application ...
VoiceOfUnreason's user avatar
11 votes

Is unit of work pattern really needed with repository pattern

The Unit-Of-Work pattern makes sense when you have a complex use case with several objects involved, often objects which map to different master-detail tables. As part of the use case, you want to ...
Doc Brown's user avatar
  • 206k
10 votes
Accepted

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

You should use a different approach. The commonly advised approaches are Use DI to inject the firestore object into your repository class instance. This way, your test framework can just inject a ...
Bart van Ingen Schenau's user avatar
9 votes

in DDD, should repositories expose an entity or domain objects?

should I return the data as an entity or domain objects/DTO Well that entirely depends on your use cases. The only reason I can think of returning a DTO instead of a full entity is if your entity is ...
MetaFight's user avatar
  • 11.6k
9 votes

Data Repository and Complex Queries (DTO)

To cut a long story short, this is mostly a matter of self-imposing a design and then trying to make something fit. Something which is very much needed, but doesn't quite fit with the design we ...
Flater's user avatar
  • 48.7k
9 votes

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

Without the full context of this article, it's impossible to say exactly what the point of it was but I think I can provide a useful answer to your question. The first bullet "Your interface ...
JimmyJames's user avatar
  • 26.8k
8 votes

Repository Pattern vs DAL Object Creation

My understanding is: DAL (Data Access Layer) refers to a layer in your software that sits between your persistence technology and your application logic. Its purpose is to keep data access concerns ...
MetaFight's user avatar
  • 11.6k
8 votes

DDD - Aggregate inheritance and repositories, how to correctly design this situation?

it's kind of weird that I can have two repositories Get used to it. It's long been considered good practice to model your use cases explicitly. From the perspective of the application, it has a ...
VoiceOfUnreason's user avatar
8 votes

Generic repository pattern +EF and unit of work

It should satisfy SOLID principles A laudable goal, but does it help you satisfy any of your software's functional and non-functional requirements? The purpose of the SOLID principles is to help you ...
Robert Harvey's user avatar
8 votes
Accepted

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

Is it acceptable to invoke business logic inside the repository layer? The DDD police are not going to come and kick down your door. But... The motivation for the repository pattern is to "decouple ...
VoiceOfUnreason's user avatar
8 votes

Should access control be implemented in controller or repository layer?

Security should be applied by your framework before the Controller. In most frameworks this means you grant access to Controller Methods. Controller The controller will have access to the ...
Ewan's user avatar
  • 74.6k
7 votes

Data Entities, Domain entities and the repositories

Okay. There is a lot to unpack here, but the I think the root cause of some of your confusion is stemming from starting this process with the physical model at the forefront. This commonly causes all ...
user3347715's user avatar
  • 3,144
7 votes

Which layer do DDD Repositories belong to?

The repository interface belongs in the domain layer. The repository implementation should be elsewhere, but the literature is not clear. Options include: infrastructure layer (probably the most ...
Paulo Merson's user avatar
7 votes

Avoiding Repository pattern - implementing Onion Architecture with DbContext only

The core argument for using repositories is to prevent leaking EF dependent code into your domain. That argument is not wrong, it just comes with a steep cost, i.e. a high-complexity uow/repo layer, ...
Flater's user avatar
  • 48.7k
7 votes
Accepted

How to structure repositories for a small number of entities?

In DDD, the general approach is to have one repository per aggregate. An aggregate is a collection of closely related concepts that together form a consistency boundary. For example an Order aggregate ...
Rik D's user avatar
  • 4,768
6 votes

If Repository Pattern is overkill for modern ORMs (EF, nHibernate), what is a better abstraction?

Most of the arguments you mention wrongly attribute to the Repository pattern features that it doesn't have. Conceptually, a Repository as originally defined in DDD is just a collection of objects ...
guillaume31's user avatar
  • 8,533
6 votes

in DDD, should repositories expose an entity or domain objects?

There's a sizable community of folks who use CQRS to implement their domains. My feeling is that, if the interface of your repository is analogous to the best practices used by them, that you won't ...
VoiceOfUnreason's user avatar
6 votes
Accepted

Hexagonal Architecture and database concurrency

The core idea of the hexagonal architecture is that the business logic defines various interfaces, and external systems are adapted to this interface. For example, if the business logic wants to be ...
amon's user avatar
  • 134k
6 votes

Data Entities, Domain entities and the repositories

It seems that you have seen someone implementing a DDD design using the architecture you mention in the question, but that is not what DDD is. That is just one of many possible implementations. I ...
Francesc Castells's user avatar
6 votes

Where to place POCOs validation - N-layers architecture

A. Where can I place the validation? Regardless of your design there are two places where validation code goes: Near input Near use You put validation near input so that you can show the user the ...
candied_orange's user avatar
6 votes
Accepted

Domain Driven Design - updating part of aggregate

Your fears are perfectly valid, and they are an everyday part of DDD. You can design your domain in many ways. For one thing, always keep in mind that the aggregate is the boundary of transactional ...
Zoran Horvat's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible