Documents injecute 1.x · Migrating from 0.x
Skip to content

injecuteType-safe dependency injection

Bring it into a legacy app, or build a new system without a framework's opinions. Plain classes, typed wiring, no decorators required, not invasive. It is easier than you think

  • Explicit scopes

    A session, a request or a transaction gets a fork with its own services. Scope services use the root's; the root can't depend on a scope's, and the compiler checks it.

Where it fits ​

A new module inside a big brownfield system ​

Mature frameworks come with opinions about modules, HTTP, configuration and lifecycle. injecute brings a container and nothing else, so a new module gets exactly the structure it needs and still plugs into the system around it.

A non-typical greenfield project ​

When a new project doesn't fit a framework's template, injecute gives you a set of tools and the flexibility to solve the problems you meet as the architecture grows: forks and modules, tags, lifecycle hooks and your own way to register services.

Code written with coding agents ​

injecute gives an agent what it needs to get the wiring right without guessing:

  • The docs of your version, in the package. llms.txt, every guide as Markdown and TSDoc with an example on every export live in node_modules/injecute, so they never drift from the code. An Agent Skill has the rules for writing, reviewing and debugging it.
  • Wiring an agent can read. Each registration lists the keys it depends on. There are no decorators, naming conventions or reflection to infer, so the agent reads what will be injected.
  • Mistakes caught in the agent's own loop. A wrong key or a missing service fails the typecheck, with "Did you mean". At runtime every error has a stable code, the resolution path and a page that says how to fix it.
  • One way per task. Each task has one recommended way, and the docs lead with it, so generated code looks the same across the codebase.
  • Short feedback loop. The typecheck shows errors early, before any test runs.

See Using injecute with AI agents to set it up.

Is it the right choice? ​

Your situationChoice
A large app that can't stop for a rewriteinjecute: adopt it module by module
A new service or module that will growinjecute: explicit, typed wiring from day one
A modular monolithinjecute: typed modules with private services
An SDK that other teams installinjecute inside, consumers get a plain object (how)
Much of the code is written by coding agentsinjecute: docs and a skill in the package, errors agents can fix
You want one framework to decide HTTP, validation and modulesA full framework such as NestJS
A small script or a typical single-page appNo container: imports are enough (why)
You need just a CRUD APIA framework with CRUD built in

A quick look ​

ts
import {
  DIContainer,
  startable,
  startLifecycle,
  type ServiceRegistry,
} from 'injecute';

// a module asks only for what it needs and registers its part of the app
const addUsers = (c: ServiceRegistry<{ db: Database }>) =>
  c.addSingleton('users', UserRepository, ['db']);

const app = new DIContainer()
  .addInstance('dbUrl', 'postgres://localhost/app')
  .addSingleton('db', Database, ['dbUrl'])
  .extend(addUsers)
  .extend(
    startable('server', HttpServer, ['users'], {
      start: (server) => server.listen(3000),
      stop: (server) => server.close(),
    }),
  );

app.get('users'); // UserRepository, typed

// start the server; on shutdown, close it, then dispose the container
const running = await startLifecycle(app);
process.once('SIGTERM', () => running.stop());

// in a test: replace the database for the whole graph, without touching `app`
await using test = app
  .fork({ isolated: true })
  .addInstance('db', fakeDb, { replace: true });

No decorators are needed, but if you want them, a recipe builds them on top of the container.

Starts and stops servers and consumers in stages, and closes every connection with one call. Works with Express, Fastify, Hono, Next.js and GraphQL, on Node.js, Deno, Bun and in browsers, with no runtime dependencies.

Released under the MIT License.