What is the best place for business logic in ASP.NET MVC when using repositories?

后端 未结 5 1748
醉酒成梦
醉酒成梦 2021-02-02 16:25

When implementing Repository for database in ASP.NET MVC project, is it correct to place business logic into it or may be better to place logic in controller class? Or use addit

5条回答
  •  孤独总比滥情好
    2021-02-02 17:18

    I agree with the above, controllers should not be responsible for business logic simply for returning the appropriate views. I use a service layer to provide business logic and view model creation so that a controller simply passes the model returned from a service to a view.

    I also ensure my view models are simple DTOs, and the service simply knows how to populate the properties appropriately.

提交回复
热议问题