Skip to content

Commit c2d66ee

Browse files
Update provider-scopes.md
1 parent 9675a31 commit c2d66ee

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

content/fundamentals/provider-scopes.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,23 @@ export class AggregateByTenantContextIdStrategy implements ContextIdStrategy {
197197
198198
> warning **Warning** Note this strategy is not ideal for applications operating with a large number of tenants.
199199
200-
With this strategy in place, you can register it somewhere in your code (as it applies globally anyway), so for example, you could place it in the `main.ts` file:
200+
The value returned from the `attach` method instructs Nest what context identifier should be used for a given host. In this case, we specified that the `tenantSubTreeId` should be used instead of the original, auto-generated `contextId` object, when the host component (e.g., request-scoped controller) is flagged as durable (you can learn how to mark providers as durable below). Also, in this example, no payload would be registered (where payload = `REQUEST`/`CONTEXT` provider that represents the "root" - parent of the sub-tree).
201+
202+
If you want to register the payload for a durable tree, use the following construction instead:
203+
204+
```typescript
205+
return {
206+
resolve: (info: HostComponentInfo) => {
207+
const context = info.isTreeDurable ? tenantSubTreeId : contextId;
208+
return context;
209+
},
210+
payload: { tenantId },
211+
}
212+
```
213+
214+
Now whenever you inject the `REQUEST` provider (or `CONTEXT` for GraphQL applications) using the `@Inject(REQUEST)`, the `payload` object would be injected (consisting of a single property - `tenantId` in this case).
215+
216+
Alright so with this strategy in place, you can register it somewhere in your code (as it applies globally anyway), so for example, you could place it in the `main.ts` file:
201217

202218
```typescript
203219
ContextIdFactory.apply(new AggregateByTenantContextIdStrategy());

0 commit comments

Comments
 (0)