Class OptionsLoaderExtensions
- Namespace
- Acuit.Pinpoint.Workstation.Configuration
- Assembly
- Acuit.Pinpoint.Workstation.Abstractions.dll
Extension members for IOptionsLoader.
public static class OptionsLoaderExtensions
- Inheritance
-
OptionsLoaderExtensions
- Inherited Members
Methods
CreateChildLoader(IOptionsLoader, IConfigurationSection)
Creates an IOptionsLoader that represents a child configuration section from a base IOptionsLoader.
public static IOptionsLoader CreateChildLoader(this IOptionsLoader optionsLoader, IConfigurationSection configurationSection)
Parameters
optionsLoaderIOptionsLoaderconfigurationSectionIConfigurationSectionThe child configuration section.
Returns
- IOptionsLoader
The new IOptionsLoader.
Remarks
configurationSection can represent any configuration section within the same configuration as optionsLoader,
not just direct children.
Exceptions
- ArgumentNullException
configurationSectionis null.- InvalidOperationException
optionsLoaderhas no configuration section.
CreateChildLoader(IOptionsLoader, Func<IConfigurationSection, IConfigurationSection>)
Creates an IOptionsLoader that represents a child configuration section from a base IOptionsLoader.
public static IOptionsLoader CreateChildLoader(this IOptionsLoader optionsLoader, Func<IConfigurationSection, IConfigurationSection> selector)
Parameters
optionsLoaderIOptionsLoaderselectorFunc<IConfigurationSection, IConfigurationSection>A selector for the child IConfigurationSection. This takes one parameter, which is the IConfigurationSection of the base IOptionsLoader, and it should return the child IConfigurationSection.
Returns
- IOptionsLoader
The new IOptionsLoader.
Remarks
selector can select any descendant member, not just direct children.
Exceptions
- ArgumentNullException
selectoris null.- InvalidOperationException
optionsLoaderhas no configuration section.
CreateChildLoader(IOptionsLoader, string)
Creates an IOptionsLoader that represents a child configuration section from a base IOptionsLoader.
public static IOptionsLoader CreateChildLoader(this IOptionsLoader optionsLoader, string key)
Parameters
optionsLoaderIOptionsLoaderkeystringThe key of the child configuration section (relative to
optionsLoader).
Returns
- IOptionsLoader
The new IOptionsLoader.
Remarks
key can represent any descendant configuration section, not just direct children.
Exceptions
- ArgumentNullException
keyis null.- InvalidOperationException
optionsLoaderhas no configuration section.
CreateChildLoader<TOptions, TMember>(IOptionsLoader, Expression<Func<TOptions, TMember>>)
Creates an IOptionsLoader that represents a child configuration section from a base IOptionsLoader.
public static IOptionsLoader CreateChildLoader<TOptions, TMember>(this IOptionsLoader optionsLoader, Expression<Func<TOptions, TMember>> memberSelector) where TOptions : notnull where TMember : notnull
Parameters
optionsLoaderIOptionsLoadermemberSelectorExpression<Func<TOptions, TMember>>A lambda expression that selects a member of the options object.
Returns
- IOptionsLoader
The new IOptionsLoader.
Type Parameters
TOptionsThe strongly-typed options object type.
TMemberThe member type.
Remarks
memberSelector can select any descendant member, not just direct children.
See GetSectionFromSelector<TOptions, TMember>(IConfigurationSection, Expression<Func<TOptions, TMember>>) for more details about member selectors.
Exceptions
- ArgumentNullException
memberSelectoris null.- InvalidOperationException
optionsLoaderhas no configuration section.- InvalidOperationException
The
memberSelectorlambda expression does not select a member via simple member accesses and/or constant int indexers.
InitializeChildCollectionOptionsAsync(IOptionsLoader, string, IEnumerable<IInitializableOptions>)
Initializes options for a collection of child members that implement IInitializableOptions.
public static Task InitializeChildCollectionOptionsAsync(this IOptionsLoader optionsLoader, string key, IEnumerable<IInitializableOptions> children)
Parameters
optionsLoaderIOptionsLoaderkeystringThe key of the child collection configuration section (relative to
optionsLoader).childrenIEnumerable<IInitializableOptions>The collection of children.
Returns
- Task
The task object representing the asynchronous operation.
Examples
public class ParentOptions : IInitializableOptions
{
public IList<ChildOptions> Children { get; } = new List<ChildOptions>();
public async Task InitializeOptionsAsync(IOptionsLoader optionsLoader)
{
await optionsLoader.InitializeChildCollectionOptionsAsync(nameof(Children), Children);
}
}
public class ChildOptions : IInitializableOptions
{
// TODO: Options members
public Task InitializeOptionsAsync(IOptionsLoader optionsLoader)
{
// TODO: Initialize options
}
}
Exceptions
- ArgumentNullException
keyis null.- ArgumentNullException
childrenis null.- InvalidOperationException
optionsLoaderhas no configuration section.- InvalidOperationException
The number of children does not match the number of child configuration sections. This will be thrown after initializing all children for which there is a child configuration section.
InitializeChildOptionsAsync(IOptionsLoader, string, IInitializableOptions)
Initializes options for a child member that implements IInitializableOptions.
public static Task InitializeChildOptionsAsync(this IOptionsLoader optionsLoader, string key, IInitializableOptions child)
Parameters
optionsLoaderIOptionsLoaderkeystringThe key of the child configuration section (relative to
optionsLoader).childIInitializableOptionsThe child member.
Returns
- Task
The task object representing the asynchronous operation.
Examples
public class ParentOptions : IInitializableOptions
{
public ChildOptions Child { get; } = new ChildOptions();
public async Task InitializeOptionsAsync(IOptionsLoader optionsLoader)
{
await optionsLoader.InitializeChildOptionsAsync(nameof(Child), Child);
}
}
public class ChildOptions : IInitializableOptions
{
// TODO: Options members
public Task InitializeOptionsAsync(IOptionsLoader optionsLoader)
{
// TODO: Initialize options
}
}
Exceptions
- ArgumentNullException
keyis null.- ArgumentNullException
childis null.
RetrieveChildFileAsync(IOptionsLoader, string)
Retrieves a file specified by a child option member.
public static Task<string?> RetrieveChildFileAsync(this IOptionsLoader optionsLoader, string key)
Parameters
optionsLoaderIOptionsLoaderkeystringThe key of the child configuration setting (relative to
optionsLoader) that specifies the file name.
Returns
Examples
public class MyOptions : IInitializableOptions
{
public string MyFileName { get; set; }
internal string MyLocalFileName { get; set; }
public async Task InitializeOptionsAsync(IOptionsLoader optionsLoader)
{
MyLocalFileName = await optionsLoader.RetrieveChildFileAsync(nameof(MyFileName));
}
}
Remarks
Once the operation completes, the Result property on the returned task object contains the local path to the retrieved file, or null if the configuration setting file name value is null or empty, or if the file could not be retrieved.
See the remarks for RetrieveFileAsync(string) for additional information (as this helper internally calls that method).
Exceptions
- ArgumentNullException
keyis null.