function Inject
Since 0.1.0
Inject(...tokens: readonly InjectToken[]): SetuClassDecorator

Declares the constructor injection tokens for a class, one per constructor argument in argument order. The DecoratorPlugin resolves each token (from the DI container or the service registry) and passes the results to the constructor.

A token is always required: type-inferred injection needs emitDecoratorMetadata, which Deno does not support, so parameter types cannot be read.

Wrap a token in Optional to let the argument receive undefined when the token has no provider.

Examples

Example 1

@Injectable()
@Inject(CAPABILITIES.DATABASE, Optional(CAPABILITIES.CACHE))
class UserRepository {
  constructor(private db: Db, private cache?: ICacheService) {}
}

Parameters

...tokens: readonly InjectToken[]

One entry per constructor argument, in argument order

Return Type

A class decorator

Usage

import { Inject } from "decorator-plugin/src/index.ts";