Skip to content

@Injectable

The @Injectable decorator marks a TypeScript class (services/*.service.ts or observers/*.observer.ts) as a managed singleton in the AGBoss dependency injection container. Injectable classes receive their constructor dependencies via deps: [...], participate in the four application lifecycle phases (OnInit, OnStart, OnStop, OnDestroy), can implement ExecutionObserver hooks (OnExecutionEnd, OnToolEnd, OnModelEnd, OnValuesOutdated), and are replaced in tests by class inheritance via override(BaseService, FakeService).

Complete @Injectable example with lifecycle hooks and DI

Section titled “Complete @Injectable example with lifecycle hooks and DI”
Option Type Required Description
deps readonly Token[] No Ordered list of constructor dependency tokens (AppEnvironment, ExecutionContext, TenantContext, ApplicationContext, Clock, Logger, ROUTER_FACTORY, or other @Injectable classes) verified against constructor parameters by TypeScript.
Section titled “What related entities work with @Injectable?”
Related Entity Import Path Purpose
OnInit, OnStart, OnStop, OnDestroy "@agboss/core" Four deterministic container lifecycle hooks executed during createApp() startup and app.close() shutdown on every container element.
ExecutionContext, TenantContext, ApplicationContext "@agboss/core" Built-in context classes injectable into any service constructor (ExecutionContext reads current step metadata via AsyncLocalStorage).
Clock & Logger "@agboss/core" Built-in time and PII-redacted structured logging singletons (Clock is replaced by VirtualClock in testWith()).
InjectionToken<T> & provide(TOKEN, value) "@agboss/core" Binds non-class configuration values or factory tokens (ROUTER_FACTORY) in @Workflow({ providers }).
override(BaseClass, SubClass) & mockOf(ServiceClass) "@agboss/core/testing" Replaces a service with a subclass or spy in testWith(), testTool(), testAction(), or testRouter().