Created
May 3, 2017 11:49
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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