Show / Hide Table of Contents

Class LambdaConfig

The LambdaConfig class is used by the Lambda function to read its configuration settings. LambdaConfig provides hiearachical access to scoped module values using the Item[String] operator. Individual values can be retrieved using the basic Read<T>(String, Func<String, T>, Func<String, T>, Action<T>) method or one of the Read* methods.

Inheritance
System.Object
LambdaConfig
Namespace: LambdaSharp
Assembly: LambdaSharp.dll
Syntax
public sealed class LambdaConfig

Constructors

LambdaConfig(ILambdaConfigSource)

Create a new instance using the provided ILambdaConfigSource instance to read configuration values.

Declaration
public LambdaConfig(ILambdaConfigSource source)
Parameters
Type Name Description
ILambdaConfigSource source

The ILambdaConfigSource instance to read configuration values from.

Exceptions
Type Condition
System.ArgumentNullException

Thrown when source is null.

Properties

Item[String]

Create a new LambdaConfig scoped to a nested section of values.

Declaration
public LambdaConfig this[string name] { get; }
Parameters
Type Name Description
System.String name

Name of the nested section.

Property Value
Type Description
LambdaConfig

A newly scoped LambdaConfig instance.

Keys

Enumerate all child keys at the current path in the hierarchy.

Declaration
public IEnumerable<string> Keys { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<System.String>

Enumeration of all nested keys.

Path

Retrieve the current hierarchy path.

Declaration
public string Path { get; }
Property Value
Type Description
System.String

Current path.

Methods

Read<T>(String, Func<String, T>, Func<String, T>, Action<T>)

Read the value for a key from ILambdaConfigSource at the current path in the hierarchy.

Declaration
public T Read<T>(string key, Func<string, T> fallback, Func<string, T> convert, Action<T> validate)
Parameters
Type Name Description
System.String key

The name of the value to read.

System.Func<System.String, T> fallback

An optional callback when the value could not be found at the current path.

System.Func<System.String, T> convert

An optional conversion from string to another type when the value was found.

System.Action<T> validate

An optional callback to validate the converted value.

Returns
Type Description
T

The found value.

Type Parameters
Name Description
T

The type of the value after conversion.

Remarks

This method should rarely be invoked directly. Instead use ReadText(String, Action<String>) and the other convenience methods.

Exceptions
Type Condition
LambdaConfigMissingKeyException

Thrown when no value is found at key and fallback is null.

LambdaConfigBadValueException

Thrown when the value fails validation.

ReadCommaDelimitedList(String, Action<IEnumerable<String>>)

Read an enumeration of comma-delimited string values for a key at the current path in the hierarchy.

Declaration
public IEnumerable<string> ReadCommaDelimitedList(string key, Action<IEnumerable<string>> validate = null)
Parameters
Type Name Description
System.String key

The name of the value to read.

System.Action<System.Collections.Generic.IEnumerable<System.String>> validate

An optional callback to validate the value.

Returns
Type Description
System.Collections.Generic.IEnumerable<System.String>

The found enumeration of string values.

Exceptions
Type Condition
LambdaConfigMissingKeyException

Thrown when no value is found at key.

LambdaConfigBadValueException

Thrown when the value fails validation.

ReadInt(String, Action<Int32>)

Read the int value for a key at the current path in the hierarchy.

Declaration
public int ReadInt(string key, Action<int> validate = null)
Parameters
Type Name Description
System.String key

The name of the value to read.

System.Action<System.Int32> validate

An optional callback to validate the value.

Returns
Type Description
System.Int32

The found int value.

Exceptions
Type Condition
LambdaConfigMissingKeyException

Thrown when no value is found at key.

LambdaConfigBadValueException

Thrown when the value fails validation.

ReadInt(String, Int32, Action<Int32>)

Read the int value for a key at the current path in the hierarchy.

Declaration
public int ReadInt(string key, int defaultValue, Action<int> validate = null)
Parameters
Type Name Description
System.String key

The name of the value to read.

System.Int32 defaultValue

A value to return if key doesn't exist.

System.Action<System.Int32> validate

An optional callback to validate the value.

Returns
Type Description
System.Int32

The found int value.

Exceptions
Type Condition
LambdaConfigBadValueException

Thrown when the value fails validation.

ReadText(String, Action<String>)

Read the string value for a key at the current path in the hierarchy.

Declaration
public string ReadText(string key, Action<string> validate = null)
Parameters
Type Name Description
System.String key

The name of the value to read.

System.Action<System.String> validate

An optional callback to validate the value.

Returns
Type Description
System.String

The found string value.

Exceptions
Type Condition
LambdaConfigMissingKeyException

Thrown when no value is found at key.

LambdaConfigBadValueException

Thrown when the value fails validation.

ReadText(String, String, Action<String>)

Read the string value for a key at the current path in the hierarchy.

Declaration
public string ReadText(string key, string defaultValue, Action<string> validate = null)
Parameters
Type Name Description
System.String key

The name of the value to read.

System.String defaultValue

A value to return if key doesn't exist.

System.Action<System.String> validate

An optional callback to validate the value.

Returns
Type Description
System.String

The found string value.

Exceptions
Type Condition
LambdaConfigBadValueException

Thrown when the value fails validation.

ReadTimeSpan(String, Action<TimeSpan>)

Read the TimeSpan value for a key at the current path in the hierarchy.

Declaration
public TimeSpan ReadTimeSpan(string key, Action<TimeSpan> validate = null)
Parameters
Type Name Description
System.String key

The name of the value to read.

System.Action<System.TimeSpan> validate

An optional callback to validate the value.

Returns
Type Description
System.TimeSpan

The found TimeSpan value.

Exceptions
Type Condition
LambdaConfigMissingKeyException

Thrown when no value is found at key.

LambdaConfigBadValueException

Thrown when the value fails validation.

ReadTimeSpan(String, TimeSpan, Action<TimeSpan>)

Read the TimeSpan value for a key at the current path in the hierarchy.

Declaration
public TimeSpan ReadTimeSpan(string key, TimeSpan defaultValue, Action<TimeSpan> validate = null)
Parameters
Type Name Description
System.String key

The name of the value to read.

System.TimeSpan defaultValue

A value to return if key doesn't exist.

System.Action<System.TimeSpan> validate

An optional callback to validate the value.

Returns
Type Description
System.TimeSpan

The found TimeSpan value.

Exceptions
Type Condition
LambdaConfigBadValueException

Thrown when the value fails validation.

ValidateIsInRange(Int32, Int32)

Creates a callback that validates that a value is in range of the specified lower and upper bounds, inclusively.

Declaration
public static Action<int> ValidateIsInRange(int lowerValue, int upperValue)
Parameters
Type Name Description
System.Int32 lowerValue

Lower bound in range.

System.Int32 upperValue

Upper bound in range.

Returns
Type Description
System.Action<System.Int32>

The validation callback to validate that a value is within the provided lower and upper bounds.

ValidateIsNegative(Int32)

Validates that the value is negative.

Declaration
public static void ValidateIsNegative(int value)
Parameters
Type Name Description
System.Int32 value

Value to validate.

Exceptions
Type Condition
LambdaConfigValidationException

Thrown when the value fails validation.

ValidateIsNonNegative(Int32)

Validates that the value is non-negative.

Declaration
public static void ValidateIsNonNegative(int value)
Parameters
Type Name Description
System.Int32 value

Value to validate.

Exceptions
Type Condition
LambdaConfigValidationException

Thrown when the value fails validation.

ValidateIsNonPositive(Int32)

Validates that the value is non-positive.

Declaration
public static void ValidateIsNonPositive(int value)
Parameters
Type Name Description
System.Int32 value

Value to validate.

Exceptions
Type Condition
LambdaConfigValidationException

Thrown when the value fails validation.

ValidateIsPositive(Int32)

Validates that the value is positive.

Declaration
public static void ValidateIsPositive(int value)
Parameters
Type Name Description
System.Int32 value

Value to validate.

Exceptions
Type Condition
LambdaConfigValidationException

Thrown when the value fails validation.

Extension Methods

AwsConverters.ReadSqsQueueUrl(LambdaConfig, String)
AwsConverters.ReadS3BucketName(LambdaConfig, String)
AwsConverters.ReadLambdaFunctionName(LambdaConfig, String)
AwsConverters.ReadDynamoDBTableName(LambdaConfig, String)
In This Article
Back to top Generated by DocFX