Copied to clipboard

Flag this post as spam?

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


  • Martin Griffiths 826 posts 1269 karma points c-trib
    Oct 19, 2015 @ 15:59
    Martin Griffiths
    0

    Recursion problem with CurrentContentAs

    I've started giving Ditto a try.

    Can "CurrentContentAs" be used with the IPublishedContentModelFactory?

    Every time i try I get a recursive loop exception.

    Martin

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Oct 19, 2015 @ 16:06
    Lee Kelleher
    0

    Hi Martin,

    I've never tried to use CurrentContentAs with the model-factory. I'm not sure of the implications it would caused.

    A potential solution would be to mark the model's property as virtual, as this will enable lazy-loading of that property.

    [CurrentContentAs]
    public virtual Whatever MyProperty { get; set; }
    

    Hopefully that should work for you?


    To be honest, I no longer recommend using the model-factory approach for Ditto. Our code started off as a prototype, and became full of unknowns, which we found difficult to support.

    We've since removed the "Ditto.ModelFactory" code from our main GitHub repo. (It now lives in a new "Ditto Labs" repo).

    Hope this helps?

    Cheers,
    - Lee

  • Martin Griffiths 826 posts 1269 karma points c-trib
    Oct 19, 2015 @ 16:09
    Martin Griffiths
    0

    Hmm right. So if I were to stop using it, how do I use it in controllers as opposed to just in the view?

    Martin.

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Oct 19, 2015 @ 16:46
    Lee Kelleher
    0

    Currently, I'm using Ditto within hijacked controllers...

    public override ActionResult Index(RenderModel model)
    {
        var myModel = model.As<MyModel>();
        return CurrentTemplate(myModel);
    }
    

    Which, depending on how many different DocTypes/models you have, can be a lot of ceremony code.

    Alternatively, there's an approach that Matt Brailsford is working on called DitFlo: https://github.com/mattbrailsford/umbraco-ditflo

    DitFlo will use the View's inherits directive to map the current content node with the target viewmodel-type.

    See Matt's repo for example code...

    e.g.

    @inherits DitFloView<MyModel>
    <html> ... </html>
    

    With this approach, you can still have your custom controllers and DitFlo will be called in the place between controller and view.

    Cheers,
    - Lee

  • Martin Griffiths 826 posts 1269 karma points c-trib
    Oct 20, 2015 @ 08:46
    Martin Griffiths
    0

    Hi Lee

    Thanks for the info. could you explain in more detail the reasoning behind sidelining Ditto.ModelFactory? Does it cause problems in real world use? Is it flawed in ways which make it unusable in certain situations?

    Your video https://www.screenr.com/PPRN describes some huge advantages of mapping a POCO to an IPublishedContent and it seems to me that it would improve workflow and simplify code even further than to just use Ditto on its own.

    I'm finding it somewhat concerning that these techniques seem to gain some ground and then fall back to Vanilla Umbraco techniques again, like in the days of the codefirst drive.

    I'm having my doubts about continuing with Mappers.

    Martin

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Oct 20, 2015 @ 09:29
    Lee Kelleher
    0

    Hi Martin,

    My 2 main issues with the Ditto / model-factory approach are...

    1. The assumption that "1 DocType = 1 POCO". My experience with that led to having large monolithic view-models... which I didn't want, so I still ended up using Ditto to make smaller models.

    It's totally possible to use both approaches, they do work side-by-side, but as a developer it feels overkill.

    2. With the Screenr video I did, when some people started to try it out, they expected support - and I wasn't ready for it. I didn't have the in-depth knowledge, time, energy nor interest (to be honest).

    In my head I was purely prototyping with the model-factory, everything was a v0.x release.

    Main issues were around infinite loops, out of memory exceptions.


    I know what you mean about having doubts, and I'm not sure what to recommend to you.

    Model mapping in Umbraco still feels like an emerging field - and I'm no expert!

    Originally releasing Ditto was to share and reuse the work done on my past client-projects.

    Cheers,
    - Lee

  • Martin Griffiths 826 posts 1269 karma points c-trib
    Oct 22, 2015 @ 10:09
    Martin Griffiths
    0

    Hi Lee

    Sorry to trouble you again...

    Going through your examples in the docs, i've stumbled across a problem.

    If I had a master template which has a lot of code wiring up the containing HTML along with stuff like say metadata, traditionally I would put these properties in the Master doctype and the children would then contain the page properties. This would save having to create meta properties for every child doctype. Kind of the point of doctype hierarchy really.

    How do I deal with this template/doctype hierarchy with the models? Following your basic example only really shows how to build models for the child elements. Surrounding properties inherited from its parent are ignored.

    How do I model this?

    Thanks

    Martin

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Oct 23, 2015 @ 16:51
    Lee Kelleher
    0

    Hi Martin,

    How do you mean "Surrounding properties inherited from its parent are ignored."?

    You can have a master model that contains the meta-data properties, and have Ditto map the values. This would be done using the built-in ValueResolvers, or developing custom ones.

    I'm happy to give examples, but would also be great to see an example of your doctype hierarchy, properties and potential class/model.

    Thanks,
    - Lee

Please Sign in or register to post replies

Write your reply to:

Draft