hn.today

Nonna – TypeScript Dependency injection without the reflection tax

nonna.nodeboot.io6 points1 comments
Screenshot of Nonna – TypeScript Dependency injection without the reflection tax

Nonna is a dependency-injection framework for TypeScript and JavaScript, paired with an ahead-of-time compiler. Its central design goal is to move dependency analysis out of runtime: the compiler uses TypeScript’s type checker to infer constructor dependencies and generate registration metadata, avoiding reflection and the need for reflect-metadata. A typical setup marks classes as injectable, imports the generated dependency file, builds an injector, retrieves services, and destroys the injector when finished. The project presents the same core container as usable across Node.js, Deno, Bun, edge environments, and integrations for frontend frameworks including React, Vue, and Svelte.

The framework emphasizes a small runtime, lifecycle control, and request isolation. It supports request-scoped dependencies tied to asynchronous execution, while guarding against those instances leaking into singletons; lifecycle hooks run predictably, with teardown in reverse order and combined error reporting. Other features include multi-providers, aliases, synchronous and asynchronous factories, and container inspection. Its performance approach includes integer-keyed registrations, cached dependency metadata, lightweight circular-dependency tracking, avoiding AsyncLocalStorage when request scope is unused, and concurrently starting independent eager providers. The project also highlights zero runtime dependencies and compatibility across runtimes as engineering constraints, and offers framework adapters, a Vite plugin, documentation, examples, and an MIT license.

Read on nonna.nodeboot.io1 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

Shaun Thomas: Burnt Toast

Shaun Thomas: Burnt Toast

PostgreSQL’s TOAST storage made the table much smaller, and counting or scanning rows was faster than with the larger uncompressed table. But reading a field inside every toasted value required far more buffer reads, showing that TOAST can trade space savings for slower access to large values. (pgedge.com)

Jepsen: ParticleDB 1.1.4

Jepsen: ParticleDB 1.1.4

Jepsen found 96 bugs in ParticleDB versions 1.1.4 through 1.1.18.11.rc-22, including crashes, data loss, and serious transaction anomalies. Most issues were fixed, but committed writes could still disappear and serializable transactions still had anomalies; Orkes says a later release resolves the remaining problems. (jepsen.io)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.