Leveraging Business Primitives in FubuMvc

If you like to use Business Primitives then you should really enjoy this feature in FubuMvc

namespace fluent.Web.Converters
{
    using System.Reflection;
    using Domain.MicroTypes;
    using FubuCore;
    using FubuCore.Binding;

    public class HexColorConverterFamily :
        IConverterFamily
    {
        public bool Matches(PropertyInfo property)
        {
            return property.PropertyType.IsTypeOrNullableOf<HexColor>();
        }

        public ValueConverter Build(IValueConverterRegistry registry, PropertyInfo property)
        {
            return context => new HexColor((string) context.PropertyValue);
        }
    }
}

Now you can use the HexColor type on your view model and this code will automatically do the conversion for you.

Here is how you register it in your FubuRegistry

  //in your FubuRegistry
  Models
    .ConvertUsing<HexColorConverterFamily>();

About Dru Sellers

Sr. Software Engineer at Dovetail Software.
This entry was posted in FubuMvc. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • http://twitter.com/jmarnold Josh Arnold

    Love it. Great to see more posts about some of “unknown” wonders!