Skip to content

Instantly share code, notes, and snippets.

@jhorsman
Created May 3, 2017 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhorsman/386e004b007f4e52c43cd0d1b0b9536f to your computer and use it in GitHub Desktop.
Save jhorsman/386e004b007f4e52c43cd0d1b0b9536f to your computer and use it in GitHub Desktop.
StaticContextClaimsProvider for DXA .NET. This lets the web application use some of the basic Context claims without a dependency on the SDL Web Context service or the Context ADF cartridge.
using System.Collections.Generic;
using Sdl.Web.Common.Configuration;
using Sdl.Web.Common.Interfaces;
namespace Dxa.Test.Context
{
/// <summary>
/// DXA Context Claims Provider using using a hardcoded set of claims for testing.
/// </summary>
public class StaticContextClaimsProvider : IContextClaimsProvider
{
public IDictionary<string, object> GetContextClaims(string aspectName, Localization localization)
{
IDictionary<string, object> claims = new Dictionary<string, object>();
// These claims are part of the claims which the ContextServiceClaimsProvider would return for a laptop with 1600x900 screen
claims.Add("ui.largeBrowser", false);
claims.Add("browser.displayHeight", 529);
claims.Add("browser.displayWidth", 1280);
claims.Add("device.displayHeight", 720);
claims.Add("device.mobile", false);
claims.Add("device.robot", false);
claims.Add("device.tablet", false);
claims.Add("device.pixeldensity", 217);
claims.Add("device.displayWidth", 1280);
claims.Add("device.pixelRatio", 1.25);
return claims;
}
public string GetDeviceFamily()
{
return null;
}
}
}
<!-- merge this configuration in your dependency injection configuration -->
<unity>
<assembly name="Dxa.Test" />
<namespace name="Dxa.Test.Context" />
<containers>
<container name="main">
<types>
<type type="IContextClaimsProvider" mapTo="StaticContextClaimsProvider">
<lifetime type="singleton" />
</type>
</types>
</container>
</containers>
</unity>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment