Set option values through AppSettings

Fixed in

EPiServer.CMS.Core 11.17.0


May 18, 2020


Jan 07, 2022


CMS Core


Closed, Acceptance tests pass


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.

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

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>

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