Facebook Pinterest
    Smart Strategy Games
    • GAMES
      • ANDROID
      • IOS
      • NINTENDO
      • PC
      • PS4
      • PS5
      • XBOX ONE
    • NEWS
      • REVIEWS
    • FAQs
    Facebook Pinterest
    Smart Strategy Games
    Smart Strategy Games » Answer » Should services return Viewmodels?

    Should services return Viewmodels?

    By Tien Nguyen

    Should services return Viewmodels?

    Services should only care about the problem domain, not the view that generates the results. Return values ​​must be expressed in terms of domain objects, not views. According to the traditional approach or theory, the ViewModel should be part of the UI layer. At least the name says so.

    Table of Contents

    • What does the service layer do?
    • Do you need a service layer?
    • What does the service layer do in MVC?
    • Should a service return a DTO?
    • What should the repository return?
    • Where should DTO be used?

    What does the service layer do?

    A service layer defines the boundary of an application [Cockburn PloP] and its set of available operations from the perspective of the client layers interface. It encapsulates the business logic of the application, controlling the transactions and coordinating the responses in the implementation of its operations.

    Do you need a service layer?

    5 answers. A service layer is not always needed. Especially if your APIs are just simple CRUD operations, for example, with no real logic or calculations needed. However, if you have an API that does some logic before querying your repository, then it should be in a separate service class.

    What does the service layer do in MVC?

    A service layer is an additional layer in an ASP.NET MVC application that mediates communication between a controller and a repository layer. The service layer contains business logic. In particular, it contains validation logic.

    Should a service return a DTO?

    Yes you should return DTO by your service layer as you have talked to your repository in service layer with domain model members and assign them to DTO and return to MVC controller and vice versa.

    What should the repository return?

    Your repositories should return domain objects and the repository client can decide if it needs to do the mapping. By assigning domain objects to view models (or something else) within a repository, you prevent your repositories client from gaining access to the underlying domain object.

    Where should DTO be used?

    A DTO is useful whenever you need to group values ​​into ad hoc structures to pass data. From a pure design perspective, DTOs are a really close to perfect solution. DTOs help further decouple the presentation of the service layer and the domain model.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Tien Nguyen
    • Website

    Related Posts

    How to Check Your Credit Report for Identity Theft? Answer

    Updated:June 22, 2023

    Are Business Credit Card Cash Rewards Taxable?

    Updated:June 22, 2023

    Which Credit Cards Waive Annual Fee for Military?

    Updated:June 22, 2023

    What is a Good Credit Card for a College Student? Opportunity

    Updated:June 22, 2023

    What Does Home Equity Line of Credit (HELOC) Mean?

    Updated:June 22, 2023

    What is meant by bit manipulation?

    Comments are closed.

    How to Check Your Credit Report for Identity Theft? Answer

    June 22, 2023

    Are Business Credit Card Cash Rewards Taxable?

    June 22, 2023

    Which Credit Cards Waive Annual Fee for Military?

    June 22, 2023

    What is a Good Credit Card for a College Student? Opportunity

    June 22, 2023
    About Us
    Smart Strategy Games

    Welcome to Smart Strategy Games, your number one source for Gaming. We’re dedicated to giving you the very Best Strategy Games with a focus on Gaming News, Gaming Reviews, Gaming Devices and NextGen Gaming.
    Useful Links
    • About Smart Strategy Games
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • Terms and Conditions
    Facebook Pinterest
    © 2023 Smart Strategy Games Designed by Inwebro

    Type above and press Enter to search. Press Esc to cancel.