alepha@docs:~/docs/reference/primitives$
cat $scope.md1 min read
#$scope
#Import
typescript
1import { $scope } from "alepha";
#Overview
Middleware that wraps the handler in an ALS (AsyncLocalStorage) context.
Gives the handler its own isolated scope — alepha.context.get() / .set() are scoped
to this execution. Useful for $pipeline where no host primitive provides a scope.
Host primitives ($action, $job, $page) include $scope by default.
Adding $scope() to their use array will throw — you're already in a scope.
typescript
1class OrderService {2 processOrder = $pipeline({3 use: [$scope(), $retry({ max: 3 })],4 handler: async (orderId: string) => {5 // alepha.context.set/get are scoped here6 return await this.orders.updateById(orderId, { status: "paid" });7 },8 });9}