Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

ConfigurationBinder: Allow specifying default values #285

@divega

Description

@divega

After PR #282 is pushed we will have the ability to bind the values of configuration sections to scalars and also entire configuration sections to structural objects, e.g.:

var timeout = config.Get<int>("timeout");

I have been looking at how this API could be used and I think a lot of friction would go away if we accepting inline default values, e.g.:

var timeout = config.Get<int>("timeout", defaultValue: 30);
// or even simpler, inferring the type from the default value:
var timeout = config.Get("timeout", defaultValue: 30);

Design & implementation notes:

  1. This default values can work with structural objects as well: an instance with default property values is passed and any properties with matching configuration values are overwritten. Do we still need the public Bind() method after this?
  2. The private BindInstance() method already returns the passed instance if no value could be read or no properties could be set. Seems that we can leverage that behavior.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions