58 votes

Is it bad practice that a controller calls a repository instead of a service?

No, think of it this way: a repository is a service (also). If the entities you retrieve through the repository handle most of the business logic there is no need for other services. Just having the ...
  • 4,468
25 votes
Accepted

Using multiple Git repositories instead of a single one containing many apps from different teams?

You're dealing with multiple teams and multiple projects. Likely decades of work went into the codebase. The short answer is that your teams and projects have varying needs and varying dependencies. ...
  • 2,023
24 votes
Accepted

When making a fix to an earlier commit, should I rebase or add a separate fix up commit?

You assume the fix does not introduce any new issues and fixes the old ones complete. But lots of fixes are worth a review on their own - and that is probably much easier when the incremental changes ...
  • 188k
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 ...
  • 126k
23 votes

How to ensure that developers see only the project modules they are working on?

Why you shouldn't do it from a team perspective The most important rules of project management regarding teams are: The project can be a success only through intense teamwork. Empowered teams that ...
  • 69.6k
19 votes
Accepted

What data should a repository return

And knowing (correct me if I'm wrong) that a repository shouldn't return a DTO Theoretically, every layer (= project in your solution) should have its own DTO objects. In that sense, your ...
  • 38.7k
18 votes

Is it bad to have many contributors in a code repository?

There are projects that have many hundreds of contributors . The Linux Kernel is one that springs to mind, so no having 40 sets of eyes improving code and fixing bugs is not a bad thing. However, ...
  • 9,865
14 votes

How Add/Create* commands should be handled in CQRS + Event Sourcing architecture

The idea in Udi's post, as I gather, is that no kind of item appears out of thin air. There is (almost) always something, or more specifically, some domain operation, which caused the item to be ...
13 votes
Accepted

How do you apply Single Responsibility principle to a repository

Whenever you have a class with more than 1 method, you can question if the SRP is fulfilled, since each of the methods will (typically) solve a different task or problem and so has a "different ...
  • 188k
13 votes
Accepted

What is the purpose of domain/business logic in classes when having repositories?

What is the purpose of domain/business logic in classes when having repositories? This is kind of like asking: What is the purpose of cars when we have garages? The reason is that Business ...
12 votes
Accepted

TDD with repository pattern

What a repository does is translate from your domain onto your DAL framework, such as NHibernate or Doctrine, or your SQL-executing classes. This means that your repository will call methods on said ...
  • 6,242
12 votes
Accepted

Are Repositories needed any longer in ASP.net 5 & EF7?

If you're adding methods to a repository like GetById GetByName GetWithIncludesABC GetWithIncludes123 Then you're better off moving to a Service Layer, and letting the Service Layer use EF ...
12 votes
Accepted

What is the difference between a Query Object and a Repository?

Your question talks about repositories being IQueryable (i.e. classes implementing the IQueryable interface), whereas your linked resource talks about repositories returning IQueryable objects. That's ...
  • 38.7k
11 votes

Is it bad practice that a controller calls a repository instead of a service?

It is not bad practice for a controller to call a repository directly. A "service" is just another tool, so use it where it makes sense. NikolaiDante commented: ... Pick the right pattern for the ...
11 votes
Accepted

Using SQL for DDD Persistence - Is Referential Integrity Mandatory?

I briefly worked at a company where they decided to not add database integrity constraints on any of the tables because they were planning on relying on the ORM and correct programming to ensure the ...
  • 9,057
10 votes

How to ensure that developers see only the project modules they are working on?

You are not Apple or Microsoft. The reason why a software developer at Apple doesn't know about all of Apple's code is that there is a bloody awful huge amount of code and nobody can know about all ...
  • 38.5k
9 votes

How do you apply Single Responsibility principle to a repository

I think you should think who has an interest to change that respective class. For example if you have an User class with an CalculatePay method and a save method. The accountant would want to change ...
9 votes

TDD with repository pattern

Don't test trivial or obvious repository methods. If the methods are trivial CRUD operations, all you're really testing is whether parameters are mapped correctly. If you have integration tests, ...
9 votes
Accepted

How do I describe the Repository pattern?

The purpose of a Repository is to provide an abstraction layer for data access. That abstraction layer should shield the user of the repository from the details of accessing the data. Things like ...
9 votes
Accepted

Storing directly in the model

When you use void updateTitle(String str) { this.title = str this.store.update(this); this.notifier.notifyAboutChange(this); } you are grouping two operations into one -- updating the ...
  • 1,946
9 votes
Accepted

Domain Objects and How they Access the Database

No, domain objects should not have any idea of the existence of a repository, or even a repository interface. If you feel the need to do this, that means there is an underlying issue with your design (...
9 votes
Accepted

How to write dynamic (non ORM) repositories that can return only the necessary data without creating many methods or data-objecs?

It would be wasteful to always fetch the entire objects. First I would question this. If your objects are well-designed and not too bloated, the performance and memory overhead of fetching them ...
  • 188k
8 votes
Accepted

How granular should we get with repositories?

Why are repositories any different from other classes? A class should have a single responsibility - a single reason to change. If you have a bundle of related data sources that are (necessarily) ...
  • 107k
8 votes
Accepted

Am I breaking SRP when I inject Factory pattern with Repository layer?

While in general injecting something is not bad and does not automatically result into breaking the SRP (nor it does in your case - you have one class which only fetches data and another constructing ...
  • 9,955
8 votes
Accepted

Calling service and repository layer from controller

If your repository layer is properly abstracted (eg, the service layer and controller can only access the repository via interfaces), then: Having the controller access the repository directly ...
  • 38.4k
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 ...
  • 11.5k
8 votes
Accepted

Is it necessary to understand the requirements of a change in order to perform an effective code review?

One of the main reasons for code review is "does it do what it is supposed to do?" Without knowing requirements (and, thus, intent) for the code you can only do a formal analysis of the code ...
  • 881
8 votes
Accepted

Releasing a project for multiple languages and package managers

It doesn't really matter which approach you choose. Both using a monorepo and separate repos are reasonably common approaches. Keeping all variants in a single repository is definitely simpler to ...
  • 126k
7 votes
Accepted

How to name complex DAL/repository methods?

Use the entire method signature to specify your intent, not just its name. Method names should represent verbs not phrases. Your method signatures can be written as: Get(object id) Get(Date day) ...
  • 2,904
7 votes
Accepted

How does the Aggregate Root concept and the Repository Pattern solve DRY in database operations?

They don't. Those concepts reduce or centralize the number of calls your business code needs to load any data objects by calling CRUD code directly, but actually the CRUD code to load or update or ...
  • 188k

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