Executing a pipeline

Injecting and Executing a Pipeline

Inject the Pipeline

If you want to execute a pipeline from somewhere else, first, inject it into the constructor. This is demonstrated in the MyController constructor, which takes an IPipeline<PipelineInputType, PipelineOutputType> as a parameter:

public MyController(IPipeline<PipelineInputType, PipelineOutputType> pipeline)
{
    _myPipeline = pipeline;
}

Execute the Pipeline

When you're ready to execute the pipeline, create an instance of the input type and populate it with your desired parameters. Then, use the _myPipeline.Execute method to process the input and get the output from the result. Here's how you can do it:

var input = new PipelineInputType()
{
    Property1 = true,
    Property2 = 42,
    Property3 = "Hello",
};
var response = await _myPipeline.Execute(input, token);
var output = response.EnsureSuccess();

response.EnsureSuccess() throws a PipelineException if any exceptions happen during the execution of the pipeline, otherwise, it will return the output (result) of the pipeline execution. The exceptions and output are also directly accessible using response.Errors and response.Output respectively.

Last updated