Skip to content

Instantly share code, notes, and snippets.

@mskutta
Created September 8, 2015 17:26
Show Gist options
  • Save mskutta/2e4253b89b0693685ab2 to your computer and use it in GitHub Desktop.
Save mskutta/2e4253b89b0693685ab2 to your computer and use it in GitHub Desktop.
Sitecore: Automatically Save Related Items using Glass Mapper
public class CompositeRelationshipSavingTask : IObjectSavingTask
{
private static readonly ConcurrentDictionary<Type, SitecoreFieldConfiguration[]> _compositeRelationships = new ConcurrentDictionary<Type, SitecoreFieldConfiguration[]>();
private SitecoreFieldConfiguration[] GetCompositeRelationshipFields(ObjectSavingArgs args)
{
var type = args.SavingContext.Config.Type;
return _compositeRelationships.GetOrAdd(type, x => CompositeRelationshipsValueFactory(args));
}
private SitecoreFieldConfiguration[] CompositeRelationshipsValueFactory(ObjectSavingArgs args)
{
return args.SavingContext.Config.Properties
.Where(property => Attribute.IsDefined(property.PropertyInfo, typeof(SitecoreCompositeRelationshipAttribute), true))
.OfType<SitecoreFieldConfiguration>()
.ToArray();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment