Skip to content

LazaroOnline/Lz.Microsoft.Configuration.LegacyProvider

Repository files navigation

Description

Microsoft's powerfull ASP.NET Core configuration extensions are also available for .Net 4.7 projects.
To make use of it for .Net 4.x in conjuction with the old App.config/Web.config sources you need a custom provider like this project.

(microsoft docs)

Usage

NuGet Installation

From Visual Studio's Package Manager Console:

PM> Install-Package Lz.Microsoft.Configuration.LegacyProvider

In code

IConfigurationBuilder configBuilder = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
	.SetBasePath(Directory.GetCurrentDirectory())
	// ...
	// With defaults section separators (.,-):
	.AddLegacyConfig()
	// Or with custom section separators:
	.AddLegacyConfig((new string[] {"."})
	// ...
	//.AddCommandLine(args)
;
IConfigurationRoot config = configBuilder.Build();
var appSettings = config.Get<MySettings>();

Benefits

The benefits of using Microsoft.Extensions.Configuration over the old System.Configuration.ConfigurationManager are:

  • Configuration binding to typed classes.
  • Adds support for multiple configuration sources with 1 line of code (CommandLine, Json, Xml, Ini, EnvironmentVariables, User-Secrets tool, Azure, etc).
  • Easily customizable configuration sources.
  • Progressive migration from dotNet 4.X to Core.

Thanks to Ben Foster for his original post.

About

Configuration provider for IConfigurationBuilder that adds the config from the old web.config/app.config legacy configurations.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages