# 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:

```csharp
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:

```csharp
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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev.ucommerce.net/readme/how-to/executing-a-pipeline.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
