Skip to content

Doctor Dose

GitHub Actions edited this page Aug 15, 2026 · 2 revisions

@Dose

Property decorator that marks a field as a dependency for Doctor to fill in.

Deno Bun Node.js

Signature

class MyHandler {
  @Dose()
  public logger!: Logger;
}

@Dose reads the property's runtime type from reflect-metadata's design:type slot and appends an entry to the class's design:injectable array. Injection happens later, when @Inoculate (or a manual Doctor.treat(this)) walks that array.

Requirements

  • The consumer's TypeScript config must have emitDecoratorMetadata: true — otherwise design:type will be undefined and @Dose throws MissingDesignTypeError.
  • reflect-metadata must be imported once at the entry point — otherwise @Dose throws MissingMetadataError.

Example

@Inoculate()
class UserHandler {
  @Dose()
  public logger!: Logger;
  @Dose()
  public db!: Database;
}

Throws

See in context

Every class in the web-app example uses @Dose — see Database.ts for multi-property injection or UserHandler.ts for a plain class that's wired up via Doctor.resolve instead of @Inoculate.


← Back to Doctor

Clone this wiki locally