Access to domain objects in a view

If I do not want to disclose the internal state of domain objects, but I need to display them, I can imagine three approaches. Which one is the most "correct" (if any?).

  • "DTO / ViewModel Approach". This seems to be a popular approach in the ASP.NET MVC world (especially using AutoMapper).
  • "decorator approach." If I have a “Client” Object, I decorate it with a “DisplayableCustomer”, which can access the internal state of the client (in most languages ​​that I have dealt with).
  • "Interface approach." Where am I doing something like this:

    class Customer {
        ....
        public void renderWith(CustomerRenderer renderer) {
             renderer.renderCustomer(address,name);
        } 
    }
    
    interface CustomerRenderer {
        public void renderCustomer(Address address, Name name);
    }
    
+3
source share
1 answer

# 1. :

  • , , . PostViewModel Post IList, .
  • , ViewModels, Ajax .
  • , Post off PostViewModel.

, ViewModels . DDD, Domain - DDD UI. / . , Domain .

MVC /. ( ) , , , . . .

, DDD, , hybird Application/UI, : Domain, Application . ViewModel .

ViewModel Application Layer DDD.


, ASP.NET MVC , . ASP.NET MVC, Microsoft, Futures.

, RenderAction:

http://eduncan911.com/blog/html-renderaction-for-asp-net-mvc-1-0.aspx

, . ViewModels, View. , , navbars .., .

RenderAction RenderPartial DDD: - , . , . DDD, MVC.

Microsoft , RenderAction ASP.NET MVC 2.0, .

...

+3

Source: https://habr.com/ru/post/1722713/


All Articles