48 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,591
36 votes

How to easily avoid circular dependencies

The premise of this question is wrong - the example does not show a circular dependency. The dependencies are CustomerController | | V | ...
Doc Brown's user avatar
  • 207k
18 votes
Accepted

Onion architecture vs 3 layered architecture

Layers, Onions, Ports, Adapters: it's all the same Since this article makes clear that onion is equivalent to 3 layer + application of the Dependency Inversion Principle (DIP), then the question ...
Kasey Speakman's user avatar
15 votes
Accepted

How is transactionality implemented in DDD applications?

A UoW might involve one ore more aggregated roots and repositories. No, absolutely not. That misses the entire point. We always change one aggregate at a time (one per transaction). Transactions ...
VoiceOfUnreason's user avatar
14 votes

Is it problematic to have a dependency between objects of the same layer in a layered software architecture?

I am comfortable to say that an object belonging to a layer can depend on objects from lower layers To be honest, I don't think you should be comfortable with that. When dealing with anything but a ...
David Arno's user avatar
  • 39.3k
11 votes
Accepted

What layer should contain interactions with external or remote resources which are not strictly data operations?

It sounds like you're describing the onion architecture, a form of n-tier architecture -- which is just a fancy way of saying it has components broken out into layers. The layer you're focusing on ...
RJB's user avatar
  • 2,110
11 votes
Accepted

Is it problematic to have a dependency between objects of the same layer in a layered software architecture?

Yes, objects in one layer can have direct dependencies among each other, sometimes even cyclic ones - that is actually what makes the core difference to the allowed dependencies between objects in ...
Doc Brown's user avatar
  • 207k
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
9 votes
Accepted

Domain vs Entities model? Domain-Driven-Design (DDD)?

It is unfortunately a popular form of DDD. I say unfortunately because it completely ignores the core principles of DDD, that is the actual modeling of the problem. Having pure data structures does ...
Robert Bräutigam's user avatar
9 votes
Accepted

External dependencies in Domain Driven Design

Yes and no. Yes, by abstracting external dependencies, you ensure that you can easily switch between different libraries. If there is a simple and straightforward way to wrap your library; go for it. ...
Flater's user avatar
  • 49.8k
8 votes
Accepted

MVC - Do I create 'joint' layers when dealing with multiple models?

In the MVC design pattern, the Controller part is responsible for translating user actions into modifications of the various Model classes that are involved in a piece of functionality. There is no ...
Bart van Ingen Schenau's user avatar
8 votes

What layer do third party API request/response models go in and what do you call them?

I guess it would have to go in the Application/Domain layer because that's where the interface for my third party API client would also be. A third party API is, by definition, not part of your ...
Flater's user avatar
  • 49.8k
8 votes
Accepted

Should I cache database requests made in validation layer?

It sounds like you have a problem with the "API" first approach (not the design pattern, but the knowledge of the infrastructure). If you forget that you have an API, how would you handle ...
Blaž Mrak's user avatar
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
6 votes

What is a good reason for separating intelligence and dao layers in a microservice?

You don't have to argue about it for "days." In that amount of time, you can actually implement a microservice of the size you're describing both ways and compare for yourself. Look at how easy the ...
Karl Bielefeldt's user avatar
6 votes
Accepted

Is My Data Access Layer Really My Domain?

Usually the naming of the layers depend on the architectural approach: The traditional layering is presentation / business logic / data access layer. Another popular variant is Fowler’s ...
Christophe's user avatar
  • 77.2k
6 votes

Domain vs Entities model? Domain-Driven-Design (DDD)?

I see this as strict separation between the domain model and the persistence model. By duplicating this model, it becomes possible to fine-tune models for their specific purpose. One represents ...
Euphoric's user avatar
  • 37.4k
6 votes
Accepted

Repository Pattern with Services Layer - Good Practice?

he divided his solution into 4 projects. Core, Data, Services and WebApi Just as a hint for finding more documentation on the subject: Core, Data, Services sounds a lot like the Domain, Persistence (...
Flater's user avatar
  • 49.8k
6 votes

Handling exogenous exceptions in layered architecture

A good practice is to throw wrapped exceptions in lower layers like the DAL. It is a good practice to throw exceptions from lower layers to report problems. They don't have to be wrapped exceptions, ...
Bart van Ingen Schenau's user avatar
6 votes
Accepted

Reduce changes needed after adding a new field to domain object

Excellent observation. Is this normal? Answer: it is unfortunately. People don't seem to notice or care about this issue. Every style / design / architecture that is based on separating technical ...
Robert Bräutigam's user avatar
6 votes
Accepted

To maintain SOLID, should data preparation, conversion, and pre-computation for purposes of saving an object, be separate from data persistence layer?

Whether your repo and your service layer should be separated or not is nothing you decide by just looking at the code and what is does. You decide this by asking yourself if the layers are ever going ...
Doc Brown's user avatar
  • 207k
6 votes
Accepted

How to propagate parameters through several architectural layers?

I think the design smell is here that you are planning to use a huge global object (or component) with mutable state. That is an invitation for all kind of errors and can cause maintenance headache. ...
Doc Brown's user avatar
  • 207k
5 votes
Accepted

In which layer should sorting logic exist

If there is only one acceptable order, business wise, decide if this ordering is an actual business rule, or is it something inherent to the data itself. For instance: A table of persons may be ...
Arseni Mourzenko's user avatar
5 votes
Accepted

How can you separate a monolith into domain-driven libraries without duplicating interfaces and still keep dependencies simple?

It seems to me your question is split into two parts. The first revolves around duplication of interfaces. The second on dependencies. First, duplication of interfaces. You probably want to ...
Price Jones's user avatar
5 votes
Accepted

Can I manage transactions in the UI

Technically, you are free to design the layers in your architecture however you want, but keep in mind transactions express some kind of business logic. If you put business logic into the UI, you ...
Doc Brown's user avatar
  • 207k
5 votes

How is transactionality implemented in DDD applications?

Not all invariants can be satisfied just by processing on the data within an aggregate. I would suggest sometimes you'd need a service-level transaction to bundle operations, at least within the same ...
user2813490's user avatar
5 votes

An alternative to a 3-layer-architecture?

It looks like your design is biased by your experience of Applications which have no functionality other than reading from/updating a database. Normally you would not expect the business logic layer'...
Ewan's user avatar
  • 75.7k
5 votes
Accepted

Does Presentation Logic constrain design of Business layer?

It's a good question. Sometimes the complexities of the real world make it harder to see the big picture, and/or are in conflict with our mental models. I'll have to digress a bit before I get to your ...
Filip Milovanović's user avatar
5 votes

Layered architecture horizontal dependencies

As usual, it all depends. If your application is basically a big ball of mud, with a single database and a complex data model underneath, where each JpaRepository is nothing more than a mirror of a ...
mtj's user avatar
  • 2,030
5 votes

Which is a good way of separating and organizing layers and subdomains code, one that highlights and facilitates a clean architecture?

If your goal is to keep related things together, here is an article of mine about packaging. In short: Packages should never depend on sub-packages. Sub-packages should never introduce new concepts, ...
Robert Bräutigam's user avatar

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