Skip to content

Configuration Settings

Marty Mathis edited this page Jan 20, 2019 · 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. For example:

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

    var resolver = new DictionaryPipelineComponentResolver(components);

    var settings = new Dictionary<string, IDictionary<string, string>>
    {
        {typeof(DelayComponent).Name, 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(string name, 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(string name, IDictionary<string, string> settings)
    {
        base.Initialize(name, 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.

Clone this wiki locally