Skip to content

MorestachioConfigExtensions

JP edited this page May 5, 2021 · 1 revision

With the Nuget package Morestachio.Configuration.Transform it is possible to add an Transformer to your IConfiguration provider that will utilize Morestachio to transform your Configuration entries.

This is helpful when you have several instances of an application or asp.core server that should behave differently or you want to transform user provided settings.

To enable the morestachio transformation you have to enable it on the IConfigurationBuilder. You can add one of two transformers and configuration them by using the extension methods in Morestachio.Configuration.Transform.MorestachioConfigExtensions.

Runtime Transformation

The extension method MorestachioConfigExtensions.UseRuntimeMorestachio() wraps the underlying IConfigurationProvider and will process each requested configuration item every time it is requested.

Buildtime Transformation

With the MorestachioConfigExtensions.UseBuildtimeMorestachio() method you will get an IConfigurationBuilder that will transform your config entries only once when the ConfigurationProvider is build.

Settings

You can set several options with the IMorestachioConfigurationBuilder returned from ether extension method.

IMorestachioConfigurationBuilder.UseOptions

This adds your own custom ParserOptions to the transformation in case you want to supply any custom formatters.

IMorestachioConfigurationBuilder.UseDiscovery

As the IMorestachioConfigurationBuilder will filter thoese items it process, you can set your custom filter here

IMorestachioConfigurationBuilder.UseValues

This allows you to add values to your expression ether globally when the key parameter is null or to a specific path where the values are only used on that path and its children.