Last week I showed you how you could reduce the amount of code you would need to write with Auto-Mapping, however what if you want to write event less configuration? How about not having to write any?

Look at our example HomePage class below, notice that is is a pure C# object with absolutely no configuration!

    public class HomePage
    {
        public virtual string Title { get; set; }
        public virtual string MainBody { get; set; }
        public virtual string Url{ get; set;}
    }

With this class we can now request data from the CMS:

    var homePage = sitecoreContext.GetCurrentItem<HomePage>();

The configuration for the classes is created the first time your request the class, afterwards the configuration is cached to improve performance.

You will need stick to the same rules defined by auto-mapping, and you can't use any static mapping.

comments powered by Disqus