Skip to content

AI agent instructions

Needle DI ships machine-readable documentation, so AI coding agents can work with it without guessing APIs.

Documentation sources

When working on Needle DI-related code, always verify against the current Needle DI documentation. Prefer current documentation over assumptions from memory.

SourceUse it for
/llms.txtCompact index of all documentation pages
/llms-full.txtThe complete documentation as a single Markdown file
/<page>.md (e.g. /concepts/binding.md)The Markdown source of a single page

For external agents, use the absolute URLs:

Every documentation page also has Copy as Markdown and Download as Markdown buttons, so you can paste a page straight into a chat.

Additional sources:

Guidance for agents

The following rules cover the mistakes LLMs most often make with Needle DI. They also apply when generating code based on knowledge of other DI libraries such as Angular, NestJS or InversifyJS.

Do

Don't

  • Don't install or import reflect-metadata or any other reflection library.
  • Don't enable experimentalDecorators or emitDecoratorMetadata, these are legacy TypeScript decorators.
  • Don't use parameter decorators such as @Inject() or @Injectable() from other frameworks, Needle DI has no parameter decorators.
  • Don't call inject() outside an injection context, use container.get() or container.runInInjectionContext() there instead.
  • Don't call inject() after an await inside container.runInInjectionContext(), the injection context is only active while the given function runs synchronously.
  • Don't create a new Container per service, bootstrap a single container (or use child containers for scoping).

Canonical example

typescript
import { Container, inject, injectable } from "@needle-di/core";

@injectable()
class FooService {}

@injectable()
class BarService {
  constructor(private fooService = inject(FooService)) {}
}

const container = new Container();
const barService = container.get(BarService);

Released under the MIT License