DataModels for Object Trees

Mar 15, 2011 at 3:55 PM

I am appreciating the introduction of DataModels as I'm trying to attach 'application state' to a domain object and was hugely uncomfortable about adding this properties to the domain objects themselves.

However, my scenario is a little more complex that the BookLibrary sample. How do you map a complex object map of Model to DataModel?



Mar 16, 2011 at 10:20 AM

I've gone with the approach outlined below. What do you think?


    /// <summary>
    /// Provides a service to ViewModels and Controllers that enables them to seperately
    /// retrieve the same instance of a DataModel for a corresponding Model object across
    /// the Applications layer
    /// </summary>
    public interface IDataModelService
        ClassDataModel GetDataModel(Class c);

    public class DataModelService : IDataModelService
        private readonly IEntityService entityService;
        private readonly ObservableCollection<ClassDataModel> classDataModels;

        public DataModelService(IEntityService entityService)
            this.entityService = entityService;

            this.classDataModels = new ConverterCollection<ClassDataModel, Class>(entityService.Classes, c => new ClassDataModel(c));

        public ClassDataModel GetDataModel(Class c)
            return classDataModels.Single(x => x.Class == c);

Mar 18, 2011 at 5:57 PM

Hi Daniel,

I like the approach you have chosen. I don't see any drawbacks at the first glance.