All Projects → ssube → noicejs

ssube / noicejs

Licence: MIT license
extremely thin async dependency injection

Programming Languages

typescript
23551 projects
Makefile
18431 projects
shell
51042 projects
javascript
137047 projects - #8 most used programming language

Projects that are alternatives of or similar to noicejs

Injector
Python dependency injection framework, inspired by Guice
Stars: ✭ 651 (+3968.75%)
Mutual labels:  dependency-injection, di
Container Ioc
Inversion of Control container & Dependency Injection for Javascript and Node.js apps powered by Typescript.
Stars: ✭ 89 (+456.25%)
Mutual labels:  dependency-injection, di
Mydi
moved to https://github.com/cekta/di
Stars: ✭ 21 (+31.25%)
Mutual labels:  dependency-injection, di
definject
Unobtrusive Dependency Injector for Elixir
Stars: ✭ 46 (+187.5%)
Mutual labels:  dependency-injection, di
Dig
A reflection based dependency injection toolkit for Go.
Stars: ✭ 2,255 (+13993.75%)
Mutual labels:  dependency-injection, di
Vcontainer
The extra fast, minimum code size, GC-free DI (Dependency Injection) library running on Unity Game Engine.
Stars: ✭ 308 (+1825%)
Mutual labels:  dependency-injection, di
Di
psr/container implementation for humans
Stars: ✭ 69 (+331.25%)
Mutual labels:  dependency-injection, di
diod
A very opinionated inversion of control (IoC) container and dependency injector for Typescript, Node.js or browser apps.
Stars: ✭ 36 (+125%)
Mutual labels:  dependency-injection, di
Hiboot
hiboot is a high performance web and cli application framework with dependency injection support
Stars: ✭ 150 (+837.5%)
Mutual labels:  dependency-injection, di
Di
PSR-11 compatible DI container and injector
Stars: ✭ 141 (+781.25%)
Mutual labels:  dependency-injection, di
Ditranquillity
Dependency injection for iOS (Swift)
Stars: ✭ 317 (+1881.25%)
Mutual labels:  dependency-injection, di
Ulfberht
🗡️ A small but powerful & opinionated DI library. Written in Kotlin, and powered by annotation processing.
Stars: ✭ 234 (+1362.5%)
Mutual labels:  dependency-injection, di
Solid
Книга о принципах объектно-ориентированного дизайна SOLID
Stars: ✭ 280 (+1650%)
Mutual labels:  dependency-injection, di
Di
Dependency injection container in go (golang)
Stars: ✭ 390 (+2337.5%)
Mutual labels:  dependency-injection, di
siringa
Minimalist dependency injection library for Python that embraces type annotations syntax
Stars: ✭ 51 (+218.75%)
Mutual labels:  dependency-injection, dependency-injection-container
Singularity
A extremely fast ioc container for high performance applications
Stars: ✭ 63 (+293.75%)
Mutual labels:  dependency-injection, di
alpha-dic
Powerful dependency injection container for node.js
Stars: ✭ 27 (+68.75%)
Mutual labels:  dependency-injection, dependency-injection-container
devonfw4flutter-mts-app
Large-Scale Flutter Reference Application. An Extension of DevonFw's My Thai Star Project
Stars: ✭ 54 (+237.5%)
Mutual labels:  dependency-injection, service-locator
Deli
Deli is an easy-to-use Dependency Injection(DI).
Stars: ✭ 125 (+681.25%)
Mutual labels:  dependency-injection, di
Ray.di
Guice style dependency injection framework for PHP
Stars: ✭ 175 (+993.75%)
Mutual labels:  dependency-injection, di

noicejs

Extremely thin, async dependency injection, now with a getting started guide.

Inspired by Google's Guice library and written in Typescript.

Features

  • async dependency resolution
  • constructor and property injection
  • modular containers with inheritance
  • named dependencies using strings or unique symbols
  • typed errors
  • typescript typedefs
  • zero runtime dependencies, bundled or otherwise
  • extensive test coverage

Contents

Status

Pipeline status Lines of Code Test coverage MIT license FOSSA Status

Open bug count Open issue count Closed issue count

Renovate badge Dependency status Dev dependency status Known vulnerabilities

Maintainability score Technical debt ratio Quality issues Language grade: JavaScript Total alerts

Releases

  • 3.x versions are compatible with Node 12+
  • 4.x versions are compatible with Node 16+

github release link github release version github commits since release

npm package link npm release version Typescript definitions

Usage

Consider a Server class that needs to fetch data from the Cache and Filesystem, but doesn't know (or need to know) how those are implemented. The following example is also part of the unit tests.

import { LocalModule } from './local';
import { NetworkModule } from './network';

class Cache {
  public get(path: string, ttl: number, fallback: () => Promise<string>): Promise<string> {
    /* ... */
  }
}

class Filesystem {
  public get(path: string): Promise<string> {
    /* ... */
  }
}

/**
 * Constructors, strings, and symbols are supported. Symbols are
 * preferred, as the most unique, but names can be convenient.
 */
@Inject(Cache.name.toLowerCase(), Filesystem.name.toLowerCase())
class Server {
  protected readonly cache: Cache;
  protected readonly filesystem: Filesystem;
  protected readonly ttl: number;

  constructor(options) {
    this.cache = options.cache;
    this.filesystem = options.filesystem;
    this.ttl = defaultTo(options.ttl, 0);
  }

  get(path: string) {
    return options.cache.get(path, this.ttl, () => options.filesystem.get(path));
  }
}

const TEST_TTL = 60;

function module() {
  if (process.env['DEBUG'] === 'TRUE') {
    return new LocalModule();
  } else {
    return new NetworkModule();
  }
}

async function main() {
  const container = Container.from(module());
  await container.configure();

  const server = await container.create(Server, {
    /* cache and filesystem are found and injected by container */
    ttl: TEST_TTL,
  });

  /* server.cache.get and server.filesystem.get will be called in order */
  const result = await server.get('some/file');
}

noicejs will collect dependencies from the decorated constructor and any superclasses, find a provider for each injected dependency, and asynchronously resolve them before calling the constructor. Any extra parameters are passed on to the original constructor, along with the container and resolved dependencies.

Build

To build a bundle and run tests:

> make

yarn
yarn install v1.17.3
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.20s.
/home/ssube/code/ssube/noicejs//node_modules/.bin/rollup --config /home/ssube/code/ssube/noicejs//config/rollup.js

src/index.ts, test/harness.ts, test/**/Test*.ts → out/...
...
created out/ in 3.3s
/home/ssube/code/ssube/noicejs//node_modules/.bin/api-extractor run --config /home/ssube/code/ssube/noicejs//config/api-extractor.json --local -v

api-extractor 7.3.8  - https://api-extractor.com/
...

API Extractor completed successfully
Success!

License

FOSSA Status

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected]