Legacy Configurations - PawelGerr/Thinktecture.Extensions.Configuration GitHub Wiki
By using the Package Thinktecture.Extensions.Configuration.Legacy
you can add the values from App.config
or Web.config
to IConfiguration
.
Use one of the extension methods on IConfigurationBuilder
.
var config = new ConfigurationBuilder()
// expecting "MyApplication.exe.config" in "bin" folder
// or rather in the same folder as the entry assembly (i.e. MyApplication.exe)
.AddAppConfig()
// expecting a "Web.config" in the same folder as the entry assembly
.AddWebConfig()
// Use this overload if the convention mentioned above differ to your application
.AddLegacyConfig("path/to/my/application.config")
.Build();
- Web.config-inheritance is not supported. For more information see: ASP.NET Configuration File Hierarchy and Inheritance
The configuration files are being parsed according to MSDN:
The XML sections not mentioned below are not guaranteed to be supported but they may :)
add
<configuration>
<appSettings>
<add key="Key1" value="Value1" />
</appSettings>
</configuration>
=> is translated to "appSettings:Key1" = "Value1"
remove
<configuration>
<appSettings>
<add key="Key1" value="Value1" />
<remove key="Key1" />
</appSettings>
</configuration>
=> removes the value for "appSettings:Key1"
clear
<configuration>
<appSettings>
<add key=""Key1"" value=""Value1"" />
<clear />
</appSettings>
</configuration>
=> removes all previously set appSettings, i.e. "appSettings:Key1"
add
<configuration>
<connectionStrings>
<add name="Name1" connectionString="ConnString1" providerName="Provider1" />
</connectionStrings>
</configuration>
=> is translated to
"connectionStrings:Name1:connectionString" = "ConnString1"
"connectionStrings:Name1:providerName" = "Provider1"
remove
<configuration>
<connectionStrings>
<add name="Name1" connectionString="ConnString1" providerName="Provider1" />
<remove name="Name1" />
</connectionStrings>
</configuration>
=> removes the values for "connectionStrings:Name1:connectionString" and "connectionStrings:Name1:providerName"
clear
<configuration>
<connectionStrings>
<add name="Name1" connectionString="ConnString1" providerName="Provider1" />
<clear />
</connectionStrings>
</configuration>
=> removes all previously set connectionStrings
There may be multiple assemblyBinding
within runtime
and multiple dependentAssembly
within assemblyBinding
.
- multiple
dependentAssembly
<configuration>
<runtime>
<assemblyBinding>
<dependentAssembly>
<assemblyIdentity name="myAssembly" publicKeyToken="token" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0 - 2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="myAssembly2" publicKeyToken="token2" culture="neutral2" />
<bindingRedirect oldVersion="1.0.0.0 - 3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
=> is translated to
"runtime:assemblyBinding:0:dependentAssembly:0:assemblyIdentity:name" = "myAssembly"
"runtime:assemblyBinding:0:dependentAssembly:0:assemblyIdentity:publicKeyToken" = "token"
"runtime:assemblyBinding:0:dependentAssembly:0:assemblyIdentity:culture" = "neutral"
"runtime:assemblyBinding:0:dependentAssembly:0:bindingRedirect:oldVersion" = "0.0.0.0 - 2.0.0.0"
"runtime:assemblyBinding:0:dependentAssembly:0:bindingRedirect:newVersion" = "2.0.0.0"
"runtime:assemblyBinding:0:dependentAssembly:1:assemblyIdentity:name" = "myAssembly2"
"runtime:assemblyBinding:0:dependentAssembly:1:assemblyIdentity:publicKeyToken" = "token2"
"runtime:assemblyBinding:0:dependentAssembly:1:assemblyIdentity:culture" = "neutral2"
"runtime:assemblyBinding:0:dependentAssembly:1:bindingRedirect:oldVersion" = "1.0.0.0 - 3.0.0.0"
"runtime:assemblyBinding:0:dependentAssembly:1:bindingRedirect:newVersion" = "3.0.0.0"
- multiple
assemblyBinding
<configuration>
<runtime>
<assemblyBinding>
<dependentAssembly>
<assemblyIdentity name="myAssembly" publicKeyToken="token" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0 - 2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding>
<dependentAssembly>
<assemblyIdentity name="myAssembly2" publicKeyToken="token2" culture="neutral2" />
<bindingRedirect oldVersion="1.0.0.0 - 3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
=> is translated to
"runtime:assemblyBinding:0:dependentAssembly:0:assemblyIdentity:name" = "myAssembly"
"runtime:assemblyBinding:0:dependentAssembly:0:assemblyIdentity:publicKeyToken" = "token"
"runtime:assemblyBinding:0:dependentAssembly:0:assemblyIdentity:culture" = "neutral"
"runtime:assemblyBinding:0:dependentAssembly:0:bindingRedirect:oldVersion" = "0.0.0.0 - 2.0.0.0"
"runtime:assemblyBinding:0:dependentAssembly:0:bindingRedirect:newVersion" = "2.0.0.0"
"runtime:assemblyBinding:1:dependentAssembly:0:assemblyIdentity:name" = "myAssembly2"
"runtime:assemblyBinding:1:dependentAssembly:0:assemblyIdentity:publicKeyToken" = "token2"
"runtime:assemblyBinding:1:dependentAssembly:0:assemblyIdentity:culture" = "neutral2"
"runtime:assemblyBinding:1:dependentAssembly:0:bindingRedirect:oldVersion" = "1.0.0.0 - 3.0.0.0"
"runtime:assemblyBinding:1:dependentAssembly:0:bindingRedirect:newVersion" = "3.0.0.0"
More information on MSDN:Configuring Services Using Configuration Files
- multiple bindings
<configuration>
<system.serviceModel>
<services>
<service name="MyService" behaviorConfiguration="behaviorConfig">
<endpoint address="address1" binding="basicHttpBinding" contract="IMyService" bindingConfiguration="MyBindingConfig" />
<endpoint address="address2" binding="basicHttpBinding2" contract="IMyService2" bindingConfiguration="MyBindingConfig2" />
</service>
</services>
</system.serviceModel>
</configuration>
=> is translated to
"system.serviceModel:services:MyService:behaviorConfiguration" = "behaviorConfig"
"system.serviceModel:services:MyService:endpoint:0:address" = "address1"
"system.serviceModel:services:MyService:endpoint:0:binding" = "basicHttpBinding"
"system.serviceModel:services:MyService:endpoint:0:contract" = "IMyService"
"system.serviceModel:services:MyService:endpoint:0:bindingConfiguration" = "MyBindingConfig"
"system.serviceModel:services:MyService:endpoint:1:address" = "address2"
"system.serviceModel:services:MyService:endpoint:1:binding" = "basicHttpBinding2"
"system.serviceModel:services:MyService:endpoint:1:contract" = "IMyService2"
"system.serviceModel:services:MyService:endpoint:1:bindingConfiguration" = "MyBindingConfig2"
- multiple binding types
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding maxBufferSize="100" maxReceiveBufferSize="200" />
</basicHttpBinding>
<netTcpBinding>
<binding name="MyBindingConfig" closeTimeout="00:01:00" />
</netTcpBinding>
</bindings>
</system.serviceModel>
</configuration>
=> is translated to
"system.serviceModel:bindings:basicHttpBinding:binding:0:maxBufferSize" = "100"
"system.serviceModel:bindings:basicHttpBinding:binding:0:maxReceiveBufferSize" = "200"
"system.serviceModel:bindings:netTcpBinding:binding:0:name" = "MyBindingConfig"
"system.serviceModel:bindings:netTcpBinding:binding:0:closeTimeout" = "00:01:00"