MVC DDD: Is it OK to use repositories together with services in the controller?

前端 未结 5 477
情歌与酒
情歌与酒 2020-12-31 15:51

most of the time in the service code I would have something like this:

public SomeService : ISomeService
{
    ISomeRepository someRepository;
    public Do(         


        
5条回答
  •  有刺的猬
    2020-12-31 16:41

    If you use repositories in your controllers, you are going straight from the Data Layer to the Presentation Layer. You lose the ability to have business logic in between.

    Now, if you say you will only use Services when you need business logic, and use Repositories everywhere else, your code becomes a nightmare. The Presentation Layer is now calling both the Business and Data Layer, and you don't have a nice separation of concerns.

    I would always go this route: Repositories -> Services -> UI. As soon as you don't think you need a business layer, the requirements change, and you will have to rewrite EVERYTHING.

提交回复
热议问题