Recipes
Load services from a folder
import { ServicesStore } from '@quik/services';
await ServicesStore.load('./services');
Every service class exported from files under the folder is imported and registered automatically.
Inject a service with a decorator
import { GetService, QService } from '@quik/services';
class OrderController {
@GetService(UserService)
private readonly users!: UserService;
}
GetService accepts a static or per-instance IQServiceScope ({ user, language, properties }) as a second
argument to resolve a scoped clone instead of the shared singleton:
class OrderController {
@GetService(UserService, (self) => ({ language: self.currentLanguage }))
private readonly users!: UserService;
}
Request/user-scoped service instances
import { ServicesStore } from '@quik/services';
const scoped = ServicesStore.session(UserService, currentUser);
session(service, user, properties?) returns a clone of the singleton bound to that user; clones with identical
serialized properties are cached and reused. Use ServicesStore.scope(service, { user, language, properties })
directly when you need to bind a language or arbitrary properties without a full user session.
Clean shutdown
import { ServicesStore } from '@quik/services';
await ServicesStore.shutdown();
Cloned/scoped instances are shut down before base singleton instances; override shutdown() on a QService
subclass to release resources (connections, timers, etc.) during teardown.