WebConfigHelper 1.0.0-beta
This is a prerelease version of WebConfigHelper.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package WebConfigHelper --version 1.0.0-beta
NuGet\Install-Package WebConfigHelper -Version 1.0.0-beta
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WebConfigHelper" Version="1.0.0-beta" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WebConfigHelper --version 1.0.0-beta
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: WebConfigHelper, 1.0.0-beta"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install WebConfigHelper as a Cake Addin #addin nuget:?package=WebConfigHelper&version=1.0.0-beta&prerelease // Install WebConfigHelper as a Cake Tool #tool nuget:?package=WebConfigHelper&version=1.0.0-beta&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Web.Config AppSettings Helper
This component allows you to get strongly typed appsetting values from the web.config file.
Example web.config app settings
<appSettings>
<add key="appVersion" value="15" />
<add key="releaseDate" value="01/02/2019" />
<add key="versions" value="1, 9, 15, 23" />
<add key="keyDates" value="01/02/2019, 01/03/2019, 01/04/2019" />
</appSettings>
Getting a setting:
var config = new WebConfigValues();
var appVersion = config.GetAppSetting<int>("appVersion");
var releaseDate = config.GetAppSetting<DateTime>("releaseDate");
// Return a comma separated list as an array
var versions = config.GetAppSettingArray<int>("versions");
var keyDates = config.GetAppSettingArray<DateTime>("keyDates");
// with a default value
var appVersion = config.GetAppSetting("appVersion", 1);
var releaseDate = config.GetAppSettingArray<DateTime>("releaseDate", DateTime.Parse("01/01/2000");
var versions = config.GetAppSettingArray("versions", new int[] { 1, 2 });
var keyDates = config.GetAppSettingArray("keyDates", new int[] { DateTime.Parse("01/01/2000"), DateTime.Parse("01/01/2001") });
Handling null values
// Either use a default value
var appVersion = config.GetAppSetting("timeout", 30);
// or use a nullable type
var appVersion = config.GetAppSetting<int?>("timeout");
// otherwise it will fail
var appVersion = config.GetAppSetting<int>("timeout");
// System.ArgumentNullException : Setting 'timeout' returned null and type System.Int32 cannot have a null value
Setting up a unit test (using Moq)
When you are creating unit tests for your web application, you can mock IWebConfigProvider allowing you to test different app settings values.
var provider = new Mock<IWebConfigProvider>();
// GetAppSetting always returns a string value
provider.Setup(x => x.GetAppSetting("appVersion")).Returns("1");
provider.Setup(x => x.GetAppSetting(versions)).Returns("1, 9, 15, 23");
var config = new WebConfigValues(provider.Object);
var appVersion = config.GetAppSetting<int>("appVersion");
var versions = config.GetAppSettingArray<int>("versions");
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
- Validation (>= 2.4.18)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.4 | 2,106 | 2/28/2019 |
1.0.3 | 1,049 | 2/4/2019 |
1.0.0-beta | 546 | 2/1/2019 |