Skip to main content

Execution Context

The ExecutionContext is the core of the engine system. It is an object that holds the state of an 'execution' or commonly known as a 'request'. It is passed to each step of the engine and can be used to store and retrieve data that is relevant to the execution.

This ExecutionContext is extended by each transport that the engine supports. For example, the HTTP transport will extend the ExecutionContext to include the request and response objects.

execution-context.ts
/**
* An interface representing the execution context for a request of any kind. It extends the `ExecutionHandler` interface and includes additional properties such as `error`, `transport`, and `scopedContainer`. The `error` property is optional and can hold an error object if an error occurred during execution. The `transport` property indicates the transport mechanism used for the execution, and the `scopedContainer` property provides access to a scoped dependency injection container for managing dependencies within the execution context.
*/
export interface ExecutionContext extends ExecutionHandler {
error?: Error;
transport: ExecutionTransport;
scopedContainer: ScopedContainer;
}

As you can see, the ExecutionContext interface includes a property called scopedContainer, responsible of Injecting Scoped Dependencies. This allows you to register and resolve dependencies that are specific to the current execution context, ensuring that they are isolated from other executions. Also contains the property transport, which indicates the transport mechanism used for the execution, such as HTTP, WebSocket, or any other supported transport. This allows you to handle different types of requests and responses based on the transport being used.

This ExecutionContext can be retrieve in any step of the workflow using the parameter @Context() decorator. See more about this in the Parameters section.