Copied to clipboard

Flag this post as spam?

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


  • Qaisar 28 posts 74 karma points
    Sep 12, 2019 @ 07:20
    Qaisar
    0

    Umbraco headrest/headless 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.

  • Qaisar 28 posts 74 karma points
    Sep 16, 2019 @ 12:48
    Qaisar
    0

    I am still strugling with a solution for this error. I found another error message "Method may only be called on a Type for which Type.IsGenericParameter is true."

    at

    ((System.RuntimeType)((System.Reflection.RuntimeMethodInfo)($exception).TargetSite).DeclaringType).DeclaringMethod

    Is there any one who has faced the similar error? or any thoughts guys ?

Please Sign in or register to post replies

Write your reply to:

Draft