2.2.1 • Published 4 months ago

@softnetics/what-the-dep v2.2.1

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

what-the-dep

compile time async dependency injection plugin

Installation

bun install @softnetics/what-the-dep

Then create a preload file in your project

// preload.ts
import { whatTheDep } from "@softnetics/what-the-dep";
import { plugin } from "bun";

plugin(whatTheDep());

and add a preload into your bunfig.toml

preload = ["./preload.ts"]

Features

  • Compile time dependency injection
  • Async dependency initialization
  • Circular dependency detection
  • Circular dependency resolution
  • Import dependency from other modules

Usage

import { Container } from "@softnetics/what-the-dep";

const container = new Container();

class A {
  constructor(public b: B) {}
}

class B {
  constructor() {}
}

container.register<A>().register<B>();

const a = await container.get<A>();

Initialize class with a factory

import { Container } from "@softnetics/what-the-dep";

const container = new Container();

class A {
  constructor(public b: B) {}
}

class B {
  constructor() {}
}

container.register<B>().register<A>(async (get) => {
  const b = await get<B>();
  return new A(b);
});

const a = await container.get<A>();

Reference to class using an interface

import { Container } from "@softnetics/what-the-dep";

const container = new Container();

interface IA {
  b: B;
}

class A implements IA {
  constructor(public b: B) {}
}

class B {
  constructor() {}
}

container.register<B>().register<IA, A>(async (get) => {
  const b = await get<B>();
  return new A(b);
});

const a = await container.get<IA>();
2.2.1

4 months ago

2.2.0

4 months ago

2.0.2

4 months ago

2.1.0

4 months ago

2.0.1

4 months ago

2.0.0

4 months ago

1.3.0

4 months ago

1.2.0

4 months ago

1.1.0

4 months ago

1.0.2

4 months ago

1.0.1

4 months ago