Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Configuring an interface for Glass Mapper can serve a couple purposes. First off, Glass Mapper can actually create dynamic proxy objects based on your interface. This means that you can actually use Glass Mapper based on an interface alone, without your own concrete implementation.</p> <p><a href="http://www.glass.lu/Mapper/Sc/Tutorials/Tutorial21" rel="nofollow noreferrer">Mike Edwards describes this here</a>.</p> <blockquote> <p>Behind the scenes Glass.Sitecore.Mapper mapper detects that you are using an interface and uses Castle Dynamic Proxies to generate a concrete class that your application can use.</p> </blockquote> <p>As he points out, this adds some overhead and does make it impossible to add additional logic.</p> <p><a href="http://www.glass.lu/Mapper/Sc/Tutorials/Tutorial17" rel="nofollow noreferrer">The other use is type inference</a>. This isn't documented well in context of interfaces, but either in calling <code>SitecoreService</code> or in your field attributes, ask Glass Mapper to infer types. For this behavior, you shouldn't need to map the interface fields. Be sure to include the <code>TemplateId</code> on the <code>SitecoreClass</code> attribute of your concrete class. This should allow you to model multiple inheritance.</p> <pre><code>public interface ISitecoreItem { Guid ID{ get; } Language Language{ get; } int Version { get; } string Url { get; } } [SitecoreClass] public partial interface IHeader : MyProject.Content.ISitecoreItem { Link LogoLink {get; set;} Image Logo {get; set;} } [SitecoreClass(TemplateId="87d5b6c1-a084-4738-be11-b4e6fe07d894")] public partial class Header : IHeader { [SitecoreId] public virtual Guid ID{ get; private set;} [SitecoreInfo(SitecoreInfoType.Language)] public virtual Language Language{ get; private set; } [SitecoreInfo(SitecoreInfoType.Version)] public virtual int Version { get; private set; } [SitecoreInfo(SitecoreInfoType.Url)] public virtual string Url { get; private set; } [SitecoreField(FieldName = "Logo Link" )] public virtual Link LogoLink {get; set;} [SitecoreField(FieldName = "Logo" )] public virtual Image Logo {get; set;} } var service = new SitecoreService(Sitecore.Context.Database); var header = service.CreateClass&lt;IHeader&gt;(false /* don't lazy load */, true /* infer type */, headerItem); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload