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.
<!-- 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>
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;
}
}
}