0.6.0 • Published 6 months ago

injecd v0.6.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

injecd

Dependency Injection made simple.

By leveraging default parameters, injecd minimizes the usual boilerplate present in TypeScript injection, while retaining type checking and automatic code completion!

installation

npm install injecd

importing

import { injecd, InjecdContainer } from "injecd";

Usage

1. Tag

const greeting$ = injecd<string>();
const class$ = injecd<A>();

2. Mark

class A {
  constructor(public greeting = greeting$.r) {}
}

3. Spawn

const container = new InjecdContainer();

4. Register

container.registerInstance(greeting$, "Hello World!");
container.registerClass(class$, A);

5. Resolve!

const instance = container.resolve(class$);

console.log(instance.greeting); // > Hello World!

Tagging with type inferrence shorthands

Instead of injecd<typeof weird>():

const weird = { weird: "untyped", inferred: "object" };
const weird$ = injecd(weird):

Instead of injecd<ReturnType<typeof weirdFactory>>():

function weirdFactory() {
  return { weird: "untyped", inferred: "object" };
}
const weird$ = injecdReturn(weirdFactory);

More information

For detailed usage examples refer to the GitHub README

0.5.0

6 months ago

0.6.0

6 months ago

0.2.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.0

1 year ago