Skip to main content

Quik Framework :: Services

Provides a service store that loads service classes from the filesystem and manages instantiation or cloning for use throughout the application.

Installation

npm install @quik/services

Usage

Define and register a service:

import { QService, ServicesStore } from '@quik/services';

class UserService extends QService {
async list() {
return [];
}
}

ServicesStore.register(UserService);
const service = ServicesStore.get(UserService);

API Highlights

  • ServicesStore.load(folder) loads services from a folder.
  • ServicesStore.register() registers service constructors.
  • ServicesStore.get(), ServicesStore.clone(), and ServicesStore.scope() access instances.
  • QService base class with session() and scope() helpers.

Dependency Resolution & Scope

Services are resolved by constructor name (or explicit string) once they are registered. The store creates a singleton instance per service on first access.

Cloned services are cached by the serialized clone properties. Use clone() or session() when you need request/user scoped behavior without impacting the singleton instance. Call ServicesStore.shutdown() during application teardown to run cleanup handlers on cloned instances first, then base instances.

Use scope() when you need to bind additional per-session state such as the active language:

const service = ServicesStore.scope(UserService, {
language: 'ro',
});

Testing & Coverage

See the root instructions for details on running pnpm run test:coverage and accessing coverage artifacts.

API Reference

Generated API documentation is available in the services API section.