Copied to clipboard

Flag this post as spam?

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


  • Qaisar 21 posts 41 karma points
    3 days ago
    Qaisar
    0

    Umbraco headrest V8

    I am trying to implement Umbraco headrest project from Matt Brailsford. I have cloned the project from github and followed the instructions for setting it up for the Umbraco v8. I setup default umbraco starter kit and tried the basic setup for headrest with mapping from Home node to HomePageViewmodel as in

    https://github.com/mattbrailsford/umbraco-headrest/tree/wip/v8

    I am getting an error : InvalidOperationException: Don't know how to map Umbraco.Web.PublishedModels.Home to test.headrestv8.HomePageViewModel.

    Here is the code for Configuration component is:

    public class HeadRestConfigComponent : IComponent
    {
        private readonly HeadRest _headRest;
    
        public HeadRestConfigComponent(HeadRest headRest)
            => _headRest = headRest;
    
        public void Initialize()
        {
            _headRest.ConfigureEndpoint(new HeadRestOptions
            {
                ViewModelMappings = new HeadRestViewModelMap()
            .For(Home.ModelTypeAlias).MapTo<HomePageViewModel>()
            });
            }
    
        public void Terminate() { }
    }
    
    public class HeadRestConfigComposer : ComponentComposer<HeadRestConfigComponent>
    { }
    

    Right now i am only trying to map one field. The code for MapDefinition is:

    public class TestHeadRestMapDefinition : IMapDefinition
    {
        public void DefineMaps(UmbracoMapper mapper)
        {
            mapper.Define<Home, HomePageViewModel>(
                (source, context) => new HomePageViewModel(),      // Constructor function
                Map);            
        }
        private void Map(Home source, HomePageViewModel target, MapperContext context)
        {
            target.ColorTheme = source.ColorTheme;
        }
    }
    
    public class TestHeadRestMapDefinisionComposer : IUserComposer
    {
        public void Compose(Composition composition)
        {
            composition.WithCollectionBuilder<MapDefinitionCollectionBuilder>()
                .Add<TestHeadRestMapDefinition>();
        }
    }
    

    The code ViewModel is:

    public class HomePageViewModel
    {
        public string ColorTheme { get; set; }
    
    }
    

    I can't figure out whats going wrong or did i set it up in a wrong way? Any help would be really appreciated.

Please Sign in or register to post replies

Write your reply to:

Draft