Skip to main content
Version: Next

injectable

This decorator targets a class and allows to provide options to set its binding.

import { injectable, BindingScope } from '@cuaklabs/iocuak';

/**
* Foo is injectable on transient scope and its service id is the type Foo itself
*/
@injectable()
class Foo {}

const bazSymbol: symbol = Symbol();

/**
* Bar is injectable on request scope. Its service id is the bazSymbol symbol.
* It's associated to the providers tag
*/
@injectable({
id: bazSymbol,
scope: BindingScope.request,
tags: [providers]
})
class Baz {}

The options parameter is described as follows:

PropertyDescriptionType
serviceIdService id to associatenumber | string | symbol
tagsTags to associatenumber | string | symbol | (number | string | symbol)[]
scopeBinding scopeBindingScope
info

Consider binding docs as reference.