Skip to main content
zerotal

Documentation


Documentation / zerotal / index / App

Variable: App

const App: object

Defined in: packages/core/src/facade/facades/App.ts:49

Static facade for the application container.

Type Declaration

container

Get Signature

get container(): Container

The live IoC container of the running application.

Returns

Container

instance()

readonly instance(): Application

The running Application instance.

Returns

Application

environment()

readonly environment(): Environment

The runtime environment: "web" | "console" | "worker" | "test" | "repl".

Returns

Environment

isProduction()

readonly isProduction(): boolean

Whether the configured app.env is a production environment.

Returns

boolean

isLocal()

readonly isLocal(): boolean

Whether the configured app.env is a local/development environment.

Returns

boolean

make()

readonly make<T>(token, consumer?): Promise<T>

Resolve a binding — or auto-wire a class via its @inject() metadata — from the container asynchronously. This is the primary resolution method.

Type Parameters

T

T

Parameters

token

BindingToken<T>

consumer?

unknown

Returns

Promise<T>

makeSync()

readonly makeSync<T>(token): T

Resolve a binding synchronously. Only works for value bindings and already-resolved singletons; throws otherwise. Prefer App.make.

Type Parameters

T

T

Parameters

token

BindingToken<T>

Returns

T

build()

readonly build<T>(ctor): Promise<T>

Construct a class by auto-wiring its dependencies, ignoring any registered binding for that token. Returns a brand-new instance every call.

Type Parameters

T

T

Parameters

ctor

(...args) => T

Returns

Promise<T>

tryMake()

readonly tryMake<K>(token): ContainerBindings[K] | undefined

Resolve a named binding without throwing — returns undefined when the token is not registered or cannot be resolved synchronously.

Type Parameters

K

K extends keyof ContainerBindings

Parameters

token

K

Returns

ContainerBindings[K] | undefined

bound()

readonly bound(token): boolean

Whether a token is registered in the container.

Parameters

token

BindingToken

Returns

boolean

bind()

readonly bind<T>(token, factory): Container

Register a transient binding — the factory runs on every resolution.

Type Parameters

T

T

Parameters

token

BindingToken<T>

factory

Factory<T>

Returns

Container

singleton()

readonly singleton<T>(token, factory): Container

Register a singleton binding — resolved once and cached for the process lifetime.

Type Parameters

T

T

Parameters

token

BindingToken<T>

factory

Factory<T>

Returns

Container

scoped()

readonly scoped<T>(token, factory): Container

Register a request-scoped binding — resolved once per request scope.

Type Parameters

T

T

Parameters

token

BindingToken<T>

factory

Factory<T>

Returns

Container

value()

readonly value<T>(token, instance): Container

Register an already-constructed value under token.

Type Parameters

T

T

Parameters

token

BindingToken<T>

instance

T

Returns

Container

alias()

readonly alias(from, to): Container

Make resolving from resolve to instead.

Parameters

from

unknown

to

unknown

Returns

Container

forget()

readonly forget(token): boolean

Remove a binding. Returns true if a binding existed for the token.

Parameters

token

BindingToken

Returns

boolean

Example

// Auto-wire a service class (resolves its @inject() graph):
const users = await App.make(UsersService);

// Resolve a named binding:
const events = await App.make("events");

// Register during boot (bootstrap/app.ts or a provider):
App.singleton(Clock, () => new SystemClock());