Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to handle view model with multiple aggregate roots?
    primarykey
    data
    text
    <p>At the moment, i got quite badly fashioned view model.</p> <p>Classes looks like this=></p> <pre><code> public class AccountActionsForm { public Reader Reader { get; set; } //something... } </code></pre> <p>Problem is that Reader type comes from domain model (violation of SRP).</p> <p>Basically, i'm looking for design tips (i.e. is it a good idea to split view model to inputs/outputs?) how to make my view model friction-less and developer friendly (i.e. - mapping should work automatically using controller base class)?</p> <p>I'm aware of AutoMapper framework and i'm likely going to use it.</p> <p>So, once more - what are common gotchas when trying to create proper view model? How to structure it? How mapping is done when there's a multiple domain object input necessary?</p> <hr> <p>I'm confused about cases when view needs data from more than 1 aggregate root. I'm creating app which has entities like Library, Reader, BibliographicRecord etc.</p> <p>In my case - at domain level, it makes no sense to group all those 3 types into <code>LibraryReaderThatHasOrderedSomeBooks</code> or whatnot, but view that should display list about ordered books for specific reader in specific library needs them all.</p> <p>So - it seems fine to create view <code>OrderedBooksList</code> with <code>OrderedBooksListModel</code> view model underneath that holds <code>LibraryOutput</code>, <code>ReaderOutput</code> and <code>BibliographicRecordOutput</code> view models. Or even better - <code>OrderedBooksListModel</code> view model, that leverages <a href="http://automapper.codeplex.com/wikipage?title=Flattening&amp;referringTitle=Home" rel="nofollow noreferrer">flattening technique</a> and has props like <code>ReaderFirstName</code>, <code>LibraryName</code> etc.</p> <p>But that leads to mapping problems because there are more than one input.<br> It's not 1:1 relation anymore where i kick in one aggregate root only.<br> Does that mean my domain model is kind a wrong?</p> <p>And what about view model fields that live purely on UI layer (i.e. enum that indicates checked tab)?</p> <p>Is <a href="https://stackoverflow.com/questions/944334/asp-net-mvc-view-with-multiple-models/944371#944371">this</a> what everyone does in such a cases?</p> <pre><code> FooBarViewData fbvd = new FooBarViewData(); fbvd.Foo = new Foo(){ A = "aaa"}; fbvd.Bar = new Bar(){ B = "bbb"}; return View(fbvd); </code></pre> <p>I'm not willing to do this=></p> <pre><code>var fbvd = new FooBarViewData(); fbvd.FooOutput = _mapper.Map&lt;Foo,FooOutput&gt;(new Foo(){ A = "aaa"}); fbvd.BarOutput = _mapper.Map&lt;Bar,BarOutput&gt;(new Bar(){ B = "bbb"}); return View(fbvd); </code></pre> <p>Seems like a lot of writing. :)</p> <hr> <p><a href="http://www.lostechies.com/blogs/jimmy_bogard/archive/2009/06/29/how-we-do-mvc-view-models.aspx" rel="nofollow noreferrer">Reading this</a> at the moment. And <a href="http://codebetter.com/blogs/jeremy.miller/archive/2008/10/23/our-opinions-on-the-asp-net-mvc-introducing-the-thunderdome-principle.aspx" rel="nofollow noreferrer">this</a>.</p> <hr> <p>Ok. I thought about this issue a lot and yeah - adding another abstraction layer seems like a solution =></p> <p><a href="http://i46.tinypic.com/fe14qp.jpg" rel="nofollow noreferrer">alt text http://i46.tinypic.com/fe14qp.jpg</a></p> <p>So - in my mind this already works, now it's time for some toying. </p> <p>ty Jimmy</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload