Skip to content

Instantly share code, notes, and snippets.

@alasvant
Created March 22, 2020 13:02
Show Gist options
  • Save alasvant/618ad6f0ed77bc4dfc85ce331407a8c0 to your computer and use it in GitHub Desktop.
Save alasvant/618ad6f0ed77bc4dfc85ce331407a8c0 to your computer and use it in GitHub Desktop.
Sample Episerver Content Delivery API configuration with new options introduced in Episerver update 296 (https://world.episerver.com/releases/episerver---update-296/)
using System;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.ServiceLocation;
namespace ContentDelivery.NewFeatures.Web.Business.Initialization
{
[InitializableModule]
[ModuleDependency(typeof(EPiServer.ContentApi.Cms.ContentApiCmsInitialization))]
public class ContentDeliveryApiInitialization : IConfigurableModule
{
public void ConfigureContainer(ServiceConfigurationContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
context.Services.Configure<EPiServer.ContentApi.Core.Configuration.ContentApiConfiguration>(config =>
{
// contentapiread is the default role for content delivery API (and it is by default set to the RequiredRole
// and it is also by default mapped to: WebAdmins, WebEditors and Administrators
// setting MinimumRoles to string.Empty allows anonymous calls
config.Default()
.SetMinimumRoles(string.Empty)
.SetMultiSiteFilteringEnabled(false)
.SetRequiredRole("contentapiread")
.SetSiteDefinitionApiEnabled(true)
.SetIncludeNullValues(false) // new option
.SetIncludeMasterLanguage(false) // new option
.SetFlattenPropertyModel(true) // new option
.SetValidateTemplateForContentUrl(false); // new option
});
}
public void Initialize(InitializationEngine context)
{
//Add initialization logic, this method is called once after CMS has been initialized
}
public void Uninitialize(InitializationEngine context)
{
//Add uninitialization logic
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment