Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • David Zweben 265 posts 749 karma points
    Feb 28, 2019 @ 20:57
    David Zweben
    0

    Benefit of Models Builder in v8?

    I was looking at the "Rendering Content" v8 documentation, and it struck me that the @Model.Value("propertyAlias") syntax is listed before the ModelsBuilder @Model.PropertyAlias syntax. To me, this suggests that @Model.Value("propertyAlias") is now the 'standard' way of accessing values.

    For a developer working in Visual Studio, given that the .Value method is quite concise, appears to support the same fallback and default value options as ModelsBuilder, and can be passed a type argument, what is the benefit of using ModelsBuilder in v8?

    Is it just that ModelsBuilder methods can be overriden with custom logic? Better Intellisense? Or should we no longer bother with ModelsBuilder at all?

    Interested to hear people's thoughts.

    -David

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Feb 28, 2019 @ 22:51
    Søren Gregersen
    1

    what is the benefit of using ModelsBuilder in v8?

    a strongly typed model - you don't need to guess all the propertynames, just use intellisense. The modelsbuilder-properties just wrap calls to Value

  • Michael Argentini 20 posts 130 karma points
    Mar 01, 2019 @ 00:14
    Michael Argentini
    102

    From my experience, the value of Intellisense for property names isn't worth the constant model regeneration and compilation when using ModelsBuilder. I have a large client website using ModelsBuilder and I plan to turn it off when they switch to Umbraco 8. It will save them money over time since using ModelsBuilder slows down development.

    That said, if you need a complex business layer where your objects use Umbraco content models as properties, or if you want to inherit from the Umbraco content models and extend them, it's a handy option.

    I guess the point is that you'll likely know when you need to use ModelsBuilder. Don't use it by default.

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Mar 01, 2019 @ 01:05
    Søren Gregersen
    2

    If you compile the website, you will get validation that it works, before deploying/running it. That’s always something :-)

  • Michael Argentini 20 posts 130 karma points
    Mar 01, 2019 @ 01:42
    Michael Argentini
    2

    True, except that using invalid models/properties in Razor doesn't always throw compilation exceptions. More of a VS flaw than anything else. But if you want compile-time validation (especially for classes), ModelsBuilder is the way to go.

  • OleP 67 posts 276 karma points
    Mar 01, 2019 @ 07:38
    OleP
    2

    By far the biggest upside from my point of view. You prevent "magic strings" by having to type the alias manually, and if you delete a property, you get a compile error instead of it silently failing.

Please Sign in or register to post replies

Write your reply to:

Draft