You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
4. That's it. Now we have a way to share request related state without needing to inject the whole `REQUEST` object.
@@ -139,6 +187,7 @@ export class AppModule {}
139
187
140
188
```ts
141
189
@@filename(cat.service)
190
+
@Injectable()
142
191
exportclassCatService {
143
192
constructor(
144
193
// We can inject the provided ClsService instance,
@@ -152,6 +201,22 @@ export class CatService {
152
201
returnthis.catRepository.getForUser(userId);
153
202
}
154
203
}
204
+
@@switch
205
+
@Injectable()
206
+
@Dependencies(AsyncLocalStorage, CatRepository)
207
+
exportclassCatService {
208
+
constructor(als, catRepository) {
209
+
// We can inject the provided ClsService instance,
210
+
this.als=als
211
+
this.catRepository=catRepository
212
+
}
213
+
214
+
getCatForUser() {
215
+
// and use the "get" method to retrieve any stored value.
216
+
const userId =this.cls.get('userId');
217
+
returnthis.catRepository.getForUser(userId);
218
+
}
219
+
}
155
220
```
156
221
157
222
3. To get strong typing of the store values managed by the `ClsService` (and also get auto-suggestions of the string keys), we can use an optional type parameter `ClsService<MyClsStore>` when injecting it.
0 commit comments