@drmercer/injector
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

@drmercer/injector

build status

A minimal, type-safe dependency injector written in TypeScript.

Example usage:

import {injectable, makeInjector} from '@drmercer/injector';

const Place = injectable<string>(() => 'world');

const Greeting = injectable<string>((inject) => `Hello, ${inject(Place)}!`);

const inject = makeInjector();

console.log(inject(Greeting)); // "Hello, world!"

See injector.spec.ts for more examples.

Goals

  • Be type-safe. No runtime errors that aren't compile-time errors.
  • Be minimal. Anything nonessential is omitted.
  • Be simple enough that you can understand it and then reimplement it yourself instead of adding another dependency to your node_modules. 🙃

License

The code in this project (e.g. all my TypeScript/JavaScript files and code snippets) is licensed under CC0. It's effectively public domain.

The English text of this README and other Markdown files in this repo (minus the code snippets) are not licensed and remain Copyright 2021 Dan Mercer, all rights reserved. (If you have questions about that, file your question as an issue on this repo and I'll try to respond promptly. I'm not trying to be a stickler, I just don't want someone plagiarizing my writing.)

Package Sidebar

Install

npm i @drmercer/injector

Weekly Downloads

2

Version

0.3.0

License

CC0-1.0

Unpacked Size

28.8 kB

Total Files

19

Last publish

Collaborators

  • drmercer