Skip to content

Configuration Settings

Marty Mathis edited this page Aug 27, 2020 · 7 revisions

All component configuration settings are passed into the pipelines using IDictionary<string, IDictionary<string, string>> constructor argument. This essentially represents a dictionary of key value pairs for each component by registered component name(component name is always the Type.Name). For example:

    var components = new Dictionary<string, IPipelineComponent>
    {
        {nameof(FooComponent), new FooComponent()},
        {nameof(DelayComponent), new DelayComponent()},
        {nameof(BarComponent), new BarComponent()},
    };

    var resolver = new DictionaryPipelineComponentResolver(components);

    var settings = new Dictionary<string, IDictionary<string, string>>
    {
        {nameof(DelayComponent), new Dictionary<string, string>
        {
            {"DelayTimeSpan", "00:00:10"}
        }}
    };

    var order = new List<Type>
    {
        typeof(FooComponent), typeof(DelayComponent), typeof(BarComponent)
    };

    var pipeline = new AsyncPipeline<ExamplePipelinePayload>(resolver, order, settings);

When the DelayComponent above is resolved, it will locate its configuration in the settings argument by name. The framework will then automatically call void Initialize(IDictionary<string, string> settings) from the IPipelineComponent interface.

Initialize can be overridden to provide custom component initialization. For example:

    private TimeSpan _delay;

    public override void Initialize(IDictionary<string, string> settings)
    {
        base.Initialize(settings);

        _delay = Settings.GetSettingValue("DelayTimeSpan", TimeSpan.FromSeconds(5), false);
    }

The framework provides two base classes for components.

AsyncPipelineComponentBase<T> : IAsyncPipelineComponent<T>

and

PipelineComponentBase<T> : IPipelineComponent<T>

Both of these abstract base classes provide a settings property, protected IDictionary<string, string> Settings { get; }. It is recommended that all components inherit from one of these base classes depending on the type of pipeline you would like to construct. These classes provide the settings initialization code that can be overridden.

The following extension methods are also provided to help you work with configuration settings within your component more easily.

    public static T GetSettingValue<T>(
        this IDictionary<string, string> settings, 
        string name, 
        bool throwOnSettingNotFound = true)

    public static T GetSettingValue<T>(
        this IDictionary<string, string> settings, 
        string name, 
        T defaultValue, 
        bool throwOnSettingNotFound = true)

    public static string GetSettingValue(
        this IDictionary<string, string> settings, 
        string name, 
        bool throwOnSettingNotFound = true)
Clone this wiki locally