umco / umbraco-ditto

Ditto - the friendly view-model mapper for Umbraco
http://our.umbraco.org/projects/developer-tools/ditto
MIT License
79 stars 33 forks source link

TypeConverters are dead. Long live ValueResolvers. #102

Closed micklaw closed 9 years ago

micklaw commented 9 years ago

Hey Dudes,

This is a follow on to the discussion in regards to https://github.com/leekelleher/umbraco-ditto/issues/97. I'm obviously jesting in the title of this post, but the more I am using Ditto, with the additions of ValueResolvers, I find myself questioning if TypeConverters and ValueResolvers are both completing the same requirement in differing ways.

I have written a couple of extensions to Ditto for Archetype and Grid binding and the more I use ValueResolvers the more I feel the usage is cleaner, with a lower barrier to use. They also appear to be able to not only complete the task of TypeConverter, but take it a step further by binding values where you have no property to get data from. Best of both worlds really. In saying that, I totally get that TypeConverters are the recommended method in .Net for TypeConversion (obv) so can see how this has its place.

So yeah, just thought I'd mention this observation. I may be missing something along the caching or perfromance line with TypeConverters and if I am then send me back to my corner. Plus I realise this is a pretty fundamental part of the implementation so would not be insignificant, just wondered on you guys two cents on this after reading the above post.

Peace.

leekelleher commented 9 years ago

@micklaw, thanks for the feedback!

The #97 discussion was good to help confirm how we're using ValueResolvers in our own implementations.

TypeConverters are still an important feature, especially from an Umbraco Core perspective, since the TryConvertTo<T> extension method makes use of them all over the place :-)


When I get around to writing the doco for it, I'll be taking the view that the usage is in the name... ValueResolvers resolve values, TypeConverters convert types.

If a developer wants to abuse that approach, (e.g. convert types within resolvers and vice versa), then that is their own decision, not our recommendation.

micklaw commented 9 years ago

Cool, as I say was just an observation after using it =) Still loving it by the way, good work.

When you mention the Umbraco Core perspective, does Ditto not use the value returned from the Umbraco type conversion? I thought the usages of TypeConverters via Umbraco and Ditto were totally separate, is there cross over of some kind between the two libraries TypeConverters?

leekelleher commented 9 years ago

Yes, sorry I didn't mean to confuse... Ditto uses the value from Umbraco (post-conversion, if any) :+1:

micklaw commented 9 years ago

Yeah, keeping a consistent pattern makes sense.

Cheers dude