Sitecore Host (the platform Sitecore Identity is built on) does have a "patching" mechanism for configuration files that is an extension of the default ASP.NET Core configuration builder.
When a Sitecore Host application such is Sitecore Identity runs, Sitecore Host performs a merge of all of the .xml
configuration files in the various folders in the application. Sitecore has provided a diagram showing the order in which values are determined:
This configuration merge process happens at application initialization, so any configuration value defined in an .xml
file could be overridden at the command line or through environment variables.
An example of how the merge process works is shown below. You'll notice that the <Debug>
and <Root>
values are both in the merged configuration and since File2.xml
is the one that takes precedence, <MyValue>
contains the value of what is in File2.xml
File1.xml
<Settings>
<Sitecore>
<Diagnostics>
<Debug>true</Debug>
<MyValue>First</MyValue>
</Diagnostics>
</Sitecore>
</Settings>
File2.xml
<Settings>
<Sitecore>
<Diagnostics>
<Root>Alt</Root>
<MyValue>Second</MyValue>
</Diagnostics>
</Sitecore>
</Settings>
Merged configuration
<Settings>
<Sitecore>
<Diagnostics>
<Debug>true</Debug>
<Root>Alt</Root>
<MyValue>Second</MyValue>
</Diagnostics>
</Sitecore>
</Settings>
As a best practice, all custom .xml
config files should be placed in the sitecoreruntime
folder. Any configuration in the sitecoreruntime
folder will take precedence over any other config file (with the exception of command line overrides and environment variables).
In addition, you can use Sitecore-style configuration patching syntax such as patch:before
, patch:after
, etc. to patch specific values. A sample is shown below:
<Settings>
<Sitecore xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sites>
<site patch:before="*[@name='website']" name="mysite" />
<site patch:after="*[@name='website']" name="mysite2" />
<site patch:delete="*[@name='website']" name="mysite2" />
<site patch:instead="*[@name='website']" name="mysite2" />
<patch:attribute name="value">
MyNewValue
</patch:attribute>
</sites>
</Sitecore>
</Settings>
Once you have your values patched as you need it, you can access the final merged/patched configuration from the injected ISitecoreConfiguration
object.
_Source: https://doc.sitecore.com/developers/92/sitecore-experience-management/en/configuration.html