Try our conversational search powered by Generative AI!

Set option values through AppSettings

Fixed in

EPiServer.CMS.Core 11.17.0

(Or a related package)

Created

May 18, 2020

Updated

Jan 07, 2022

Area

CMS Core

State

Closed, Acceptance tests pass


Description

It is now possible to configure option types (.net types with OptionsAttribute) through use of AppSettings. There are two variants of this, if appsetting key is using the prefix 'episerver:setoption' then will the code be applied inside ConfigurationInitialization.Configure method. This means appsettings override values originating in config sections but code that run inside another configurable module with a module dependency set as [ModuleDependency(typeof(ConfigurationInitialization))] will overwrite the values specified with 'episerver:setoption'. AppSettings with prefix 'episerver:overrideoption' will be applied in the end of the configuration and will override values from all IConfigurableModule.Configure implementations.

Example:
<appSettings>
<add key="episerver:setoption:MyNamespace.MyOption.AString,MyAssembly" value="fromAppsettings" />
<add key="episerver:overrideoption:MyNamespace.MyOption.AString,MyAssembly" value="fromAppsettings" />
</appSettings>

The format of the key is first the prefix "episerver:setoption" or 'episerver:overrideoption', then it is the fullname of the .NET type and a property on the option class. Then the assembly name of the assembly where the option type is defined, as:
<prefix>:<FullName>.<PropertyName>, <AssemblyName>

Limitations:
Only "simple" property types are supported, like string, int, bool, enums etc.