-
Notifications
You must be signed in to change notification settings - Fork 7
Home
A cross-platform library supporting .NET 4.6 and netstandard2.0
, PipelineFramework allows you to construct complex linear workflows out a set of components you create.
Pipelines are constructed using a set of components that are resolved using implementations of the following interface:
public interface IPipelineComponentResolver
{
T GetInstance<T>(string name) where T : IPipelineComponent;
}
Both pipeline types AsyncPipeline<T>
and Pipeline<T>
provide two constructors which can be used to construct pipelines.
public AsyncPipeline(
IPipelineComponentResolver resolver,
IEnumerable<string> componentNames,
IDictionary<string, IDictionary<string, string>> settings)
public AsyncPipeline(
IPipelineComponentResolver resolver,
IEnumerable<Type> componentTypes,
IDictionary<string, IDictionary<string, string>> settings)
and
public Pipeline(
IPipelineComponentResolver resolver,
IEnumerable<string> componentNames,
IDictionary<string, IDictionary<string, string>> settings)
public Pipeline(
IPipelineComponentResolver resolver,
IEnumerable<Type> componentTypes,
IDictionary<string, IDictionary<string, string>> settings)
The first argument, IPipelineComponentResolver
, is used to resolve any components that are requested. The second argument, IEnumerable<string>
or IEnumerable<Type>
, is used to instruct the resolver which components should be resolved and in what order. The third argument, IDictionary<string, IDictionary<string, string>>
, provides configuration settings to the components.
When using IEnumerable<string>
type as second argument, the framework will use each string as an argument to the resolver
method T GetInstance<T>(string name)
directly. When using IEnumerable<Type>
, the framework will use Name property of each Type.
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);
}