-
Notifications
You must be signed in to change notification settings - Fork 0
Quick Start
Quick Start
There are only three easy steps to follow when you want to use SmartDev.ConfigurationMapper
.
1. Install the NuGet package
When you use Visual Studio, in the package manager console, type
PM> Install-Package SmartDev.ConfigurationMapper -Pre
Or, when you use ASP.NET 5 with command line tooling (i.e. on a Mac or on Linux), add it to the dependencies
section of your project.json
:
"dependencies": {
"SmartDev.ConfigurationMapper": "1.0.0-beta3-*"
},
2. Create a POCO for your Configuration Values
public class MyApplicationConfiguration
{
public string Foo { get; set; }
public string Bar { get; set; }
}
3. Map your POCO from the ASP.NET 5 Configuration
While using SmartDev.ConfigurationMapper;
, the easiest way to map the configuration values to your POCP is using the .Map<>()
extension method provided on the Microsoft.Framework.ConfigurationModel.IConfiguration
interface. Note: It is assumed that you have an IConfiguration
instance available (i.e. through Dependency Injection).
// map the config values from an configuration object:
var config = configuration.Map<MyApplicationConfiguration>();
// use the config values
DoSomethingWith(config.Foo);
DomeSomethingOtherWith(config.Bar);
That's it. All values that can be obtained from the configuration by key names that match to property names on your POCO, will be automatically converted to the corresponding property types and set on the properties.
More advanced concepts, like defining alternating Key names for your properties, scoping your object to sub keys in the configuration, support for arrays and enums etc. can also be easily applied.