My typical build-out for Glass and fluent config is to use an interface and map file (using SitecoreGlassMap) for modeling, but I know if I need to use the model to add data to Sitecore I can't use the interface type. From a best practice standpoint, if my model is to be used for adding content, should I map only to the concrete class? For example, if I have this interface:
public interface ITemplate {
string Field { get; set; }
}
And then I have this mapping:
public class TemplateMap : SitecoreGlassMap<ITemplate> {
public override void Configure() =>
Map(config => {
config.Field(f => f.Field).FieldName("Field");
});
}
If I need to add a concrete class of Template like so:
public class Template : ITemplate {
public string Field { get; set; }
}
Will the fluent mapping capture both the interface and the concrete class? Or would I need to reconfigure the map to be SitecoreGlassMap<Template>
instead, and I should just use that for all my references to this template? Basically, do I need to go back through my code and change any ITemplate item = GetItem<ITemplate>()
reference to use the concrete class instead? I suppose I could create a second mapping file for the concrete class, but that seems redundant and inefficient.