All notes
Nancy

MVVM

A code-review-like discussion on NancyFx.slack.com:

matthewpeck 9:43 PM
@silencej leaking your persistence model outside your application is extremely anti-pattern. You want to map your entities to view models for delivery to the view or service client.

silencej 9:42 AM
@matthewpeck I understand. I was from Django world, and perfer Do-not-Repeat-Yourself right now. Maybe I have to resort to View Model in future. (edited)

matthewpeck 9:42 AM
DRY is orthogonal to the concept of defining the model for the use
your persistence model exists to serve as the persistence implementation to your authoritative domain model
your view model exists to serve as the format that matches, in lock step, with your view structure
the two are fundamentally divergent, though of course rooted in commonality
the domain model is intrinsic to the system - the view model is one-to-one with the view
if ever the two matched directly, i would be extremely skeptical that the system were designed well
so in a properly-design application, the persistence model is rehydrated to the domain model, which is mapped to the view model for a particular view
got two views displaying overlapping data? two different view models (edited)

silencej 9:45 AM
Is this MVVM pattern?

matthewpeck 9:45 AM
deliver to the view _precisely_ the data it needs, ready for direct and immediate use
this is MV* pattern
because what the C in MVC does is retrieve the VM
but more broadly, it's single responsibility principle
the model of the view is exactly that which the view needs, no more and no less
it is never the responsibility of the view to translate the persistence or domain models to the view model
if you have code that takes the response of a service and translates it for use in the view, you have bad code (edited)

silencej 9:48 AM
I see. I will think carefully about it. Nice code review :stuck_out_tongue_winking_eye: Thank you.

matthewpeck 9:49 AM
i guarantee you, if you follow these tenets, you will write _less_ code with fewer bugs that is more extensible

silencej 9:52 AM
Got it~

SO. Get query values.


Get["/query"] = parameters =>
{
    var rawStart = Request.Query.start;
    var rawEnd = Request.Query.end;
    var metrics = Request.Query.metrics;

    return Response.AsJson(0);
};