Copied to clipboard

Flag this post as spam?

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

  • Jeroen Wijdeven 31 posts 72 karma points MVP
    Jun 13, 2015 @ 15:26
    Jeroen Wijdeven

    Strongly Typed Models (summary)

    This thread is a result of the open space about strongly typed models we had at Codegarden '15. I try to give you an overview of what the possibilities are. I try to update this post from time to time, so this can be a good starting point for anyone who like to start using strongly typed models. Umbraco has more possibilities to handle the "Models" but this thread is not meant to be a discussion for if you have to use Typed Models or not. The beauty of Umbraco is that it doesn't force anything and that it gives interfaces to serve everybody. If you like to decide what approach you have to use start looking here: If you are decide to go strongly typed than this thread could be your starting point.

    My conclusion of what's being discussed at CG15
    It depends on the developer if you like to use strongly typed models (with or without a model builder). And if you're going to use it, it depends on you which implementation fits your way of working best. There is no good or bad and HQ is not going to force you to use one or the other. The core needs to serve us with a minimum of interfaces / apis and thats already been done with the IPublishedContentModelFactory. Some people came up with the idea to have a better overview of packages and dicussions about this subject on and hopefully this is a start.

    What models builders / mappers do we have.

    First of all using strongly typed models doesn't need you to use an IPublishedContentModelFactory implementation and it doesn't need to have a models builder either. However one of the advantages of having an implementation of the IPublishedContentModelFactory is that created models are cached within the new cache system. Another is that all IPublishedContent in your system is a typed equivalent so you don't need to map anything over and over again. An advantage of having a models builder is that you don't need to type everything your self after creating / changing documenttypes. So what do we have?

    Zbu.ModelsBuilder is a Models builder. You can either run it from command line or from Visual Studio by using the Visual Studio extension. While building models you need to have Umbraco running, because it's looking which .net types are returned by the property value converters. The builder generates classes with properties containing the right ".GetPropertyValue

    Muffin is actually a framework which has a strong focus on separation of concerns, unit testability etc. Muffin also has a models builder and its own implementation of the IPublishedContentModelFactory. This implementation returns Castle Dynamic Proxies to keep your classes as plain as possible and serves you with a late binding senario. Currently the models builder it self depends on uSync. The builder is started within visual studio (T4 - run custom tool). Theoretically Muffin doesn't force you to use it's own implementation of the IPublishedContentModelFactory, and you can use others as well. Watch a youtube video here: ..

    Ditto is a mapper and it doesn't currently have a Models builder. There is an implementation of the IPublishedContentModelFactory using Ditto available as a separate library. It can map IPublishedContent to none related Umbraco objects but also to PublishedContentModels. From start Ditto is an early binder. But the new version of Ditto can also create proxies to serve you a late binding senario. They created there own implemantion of serving proxies by using Reflection.Emit. There is written much about Ditto but the best starting point is here:

    Umbraco Mapper
    Umbraco Mapper is what it says a mapper as well. It doesn't have an implementation of the IPublishedContentModelFactory and it doesn't have a models builder either. Off course you are free to write your own based on it. Umbraco Mapper maps IPublishedContent to objects (not related to any form of Umbraco). Umbraco Mapper doesn't have a Models builder. It's very well documentent in the README file on github:

    A totally different approach is USiteBuilder. It doesn't have a model builder, it doesn't have an implementation of the IPublishedContenModelFactory and it isn't is a mapper either. USiteBuilder is a code first site builder. You can define objects and based on that the documenttypes are generated. This results in a situation where your deployments are automated as well. USiteBuilder is maintained on github:

    Every completion or comments on wrong assumptions I made are very welcome and so are dicussions about which approuch you like or not like.

  • Jeroen Wijdeven 31 posts 72 karma points MVP
    Jun 14, 2015 @ 07:00
    Jeroen Wijdeven

    Added you USiteBuilder to the list.

  • Thomas 35 posts 133 karma points c-trib
    Jun 15, 2015 @ 13:19

    Firstly, thanks for putting together this discussion and the space at cg15. I think that for the most part it seems that the demand is split into...

    • retaining the current dynamic options but perhaps making them easier to work with
    • allowing for strongly typed models if you choose to work in that manner, either through an extension package or something that is supported by the Core

    Here is a fairly comprehensive post on the options from Andy Butland last year (who wrote the Umbraco Mapper package) and it is mostly still relevant although ModelsBuilder and Ditto have since opened up this debate a bit further...

Please Sign in or register to post replies

Write your reply to: