Benjamin Schaefer
Apr 13, 2017
  4878
(3 votes)

Working with Episerver Social References

Episerver Social is a stand-alone platform that provides unparalleled control over the construction of models used to deliver social content. Social has two ways to uniquely reference content stored within it.

  • An Id that is generated when a model is persisted into the Social system.
  • A Reference, a means of identifying relationships between social content and application entities.

One aspect of building a maintainable social application is ensuring that you apply a consistent scheme for representing the relationships between your application and its social content. References must be capable of uniquely identifying your application's entities, being easily interpreted by your application, and robust enough to support your application's inevitable future changes.

Example use cases for References might include the following:

  • Referencing a third-party platform that Social is interacting with (for example, Episerver, Ektron, SAP, etc.)
  • Referencing a third-party provider that Social is being used with (for example, Commerce, Cms, ERP, etc.)
  • Referencing unique user Ids
  • Referencing unique product/variant Ids

To ensure the consistent construction of a reference a developer might find it advantageous to standardize the way references are created. Here are three guidelines to help you to create references.

1. Build an easily expandable mechanism for handling strings that will be used most often.

//Outline the standard platforms that will be in use with Social.
public static class Platform
{
    public const string Episerver = "Episerver";
    public const string Ektron = "Ektron";
    public const string Salesforce = "Salesforce";
    public const string SAP = "SAP";
    public const string Microsoft = "Microsoft";
}
//Outline the standard providers that exist for your platforms and will be referenced by your builder. 
public static class Provider
{ 
    //Episever and Ektron
    public const string CMS = "CMS";
    public const string Commerce = "Commerce";
 
    //Salesforce
    public const string Demandware = "Demandware";
    public const string SalesCloud = "SalesCloud";
    public const string Pardot = "Pardot";
 
    //SAP
    public const string ERP = "ERP";
    public const string Anywhere = "Anywhere";
 
    //Microsoft
    public const string Sharepoint = "Sharepoint";
    public const string Dynamics = "Dynamics";
} 

2. Build an efficient way to assemble the relevant strings needed for your Social References.

// This class builds up a string from the relevant details of a product in a third party system.
public class ProductReferenceBuilder
{
    public string Platform { get; set; }
    public string Provider { get; set; }
    public string ProductId { get; set; }
    public string Variant { get; set; }

    public ProductReferenceBuilder AddPlatform(string platform)
    {
        Platform = platform;
        return this;
    }
    
public ProductReferenceBuilder AddProvider(string provider)     {         Provider = provider;         return this;     }
public ProductReferenceBuilder AddProductId(string productId)     {         ProductId = productId;         return this;     }
public ProductReferenceBuilder AddVariantId(string variant)     {         Variant = variant;         return this;     }
  public Reference Build()     {         ProductReferenceValidation();         var referenceString = $"Product://{Platform}/{Provider}/{ProductId}/{Variant}";         return Reference.Create(referenceString);     }
private void ProductReferenceValidation()     {         if (string.IsNullOrWhiteSpace(Platform) ||         string.IsNullOrWhiteSpace(Provider) ||         string.IsNullOrWhiteSpace(ProductId) ||         string.IsNullOrWhiteSpace(Variant))         {             throw new Exception("Missing field value for ProductReference");         }     }
// This class builds up a string from the relevant details of a user in a third-party system. public class UserReferenceBuilder {     public string Platform { get; set; }     public string Provider { get; set; }     public string UserId { get; set; }
public UserReferenceBuilder AddPlatform(string platform)     {         Platform = platform;         return this;     }
  public UserReferenceBuilder AddProvider(string provider)     {         Provider = provider;         return this;     }
public UserReferenceBuilder AddUserId(string userId)     {         UserId = userId;         return this;     }
public Reference Build()     {         ProductReferenceValidation();         var referenceString = $"User://{Platform}/{Provider}/{UserId}";         return Reference.Create(referenceString);     }
private void ProductReferenceValidation()     {         if (string.IsNullOrWhiteSpace(Platform) ||         string.IsNullOrWhiteSpace(Provider) ||         string.IsNullOrWhiteSpace(UserId))         {             throw new Exception("Missing field value for UserReference");         }     }
private void ProductReferenceValidation()     {         if (string.IsNullOrWhiteSpace(Platform) ||         string.IsNullOrWhiteSpace(Provider) ||         string.IsNullOrWhiteSpace(UserId))         {             throw new Exception("Missing field value for UserReference");         }     } }

3. Add unit tests for your reference related classes to ensure that the creation of a reference matches what is expected.

[TestClass]
public class ProductBuilderTest
{
    [TestMethod]
    public void ProductReferenceBuilder_Build_ReturnsProperlyConstructedReference()
    {
         var expectedProductReference = Reference.Create("Product://Episerver/Commerce/ProductId/VarientId");
         var actualProductReference = new ProductReferenceBuilder().AddPlatform(Platform.Episerver)
                                                                   .AddProvider(Provider.Commerce)
                                                                   .AddProductId("ProductId")
                                                                   .AddVariantId("VarientId")
                                                                   .Build();
        Assert.IsTrue(expectedProductReference == actualProductReference);
    }

 

    [TestMethod]
    public void UserReferenceBuilder_Build_ReturnsProperlyConstructedReference()
    {
        var expectedProductReference = Reference.Create("User://Microsoft/Dynamics/UserId");
        var actualProductReference = new UserReferenceBuilder().AddPlatform(Platform.Microsoft)
                                                               .AddProvider(Provider.Dynamics)
                                                               .AddUserId("UserId")
                                                               .Build();
        Assert.IsTrue(expectedProductReference == actualProductReference);
    }
}

By employing these guidelines, developers can create reusable code to help construct references consistently.
Additional information on Episerver Social Reference can be found at:
http://world.episerver.com/documentation/developer-guides/social/social_platform-overview/discovering-the-platform/#referenceandIDs.
 

Apr 13, 2017

Comments

Sep 7, 2018 05:29 PM

192.168.l.254

Please login to comment.
Latest blogs
Four database surprises when upgrading from CMS 11 to CMS 13

We're in the middle of migrating a fairly large site from CMS 11 / .NET Framework to CMS 13 / .NET 10. The code migration is one thing, but the...

Per Nergård (MVP) | Jun 12, 2026

Designing ODP Real-Time Audiences for CMS Personalization and Experimentation

A practical look at when to use ODP Real-Time Audiences, how to build them, and how they fit into CMS personalization and Feature Experimentation.

Wojciech Seweryn | Jun 11, 2026 |

Unlock Experimentation with Content Variations in CMS 13

Part 1 argued that Content Variations is the CMS 13 feature that didn't get the keynote but should have. This is the follow-up: wiring those...

Piotr | Jun 11, 2026

umage.ai is now an Optimizely Silver Solution Partner

umage.ai is officially an Optimizely Silver Solution Partner. The badge formalises an alignment that was already there — agent-driven Optimizely wo...

Allan Thraen | Jun 10, 2026 |