2.1.2 โ€ข Published 4 months ago

conteneur v2.1.2

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

ConteneurJS

npm npm CI

TypeScript Inversion of Control container for Dependency Injection.

It supports Functions and Classes, Scoped Containers, Transient and Singleton Strategies, and Cyclic Dependency Detection.

  • ๐Ÿชถ 0.9KB minified
  • ๐Ÿงฉ Zero dependencies
  • ๐Ÿ“ฆ TypeScript and ESM
  • ๐Ÿงช 100% Test Coverage
  • ๐ŸŒ Runtime Agnostic (Browser, Node, Deno, Bun, AWS, Vercel, Cloudflare, ..)

๐Ÿš€ Usage

import { createContainer } from 'conteneur'

const container = createContainer()

container.register({
  dataService: [createDataService],
  reportService: [createReportService],
})

const reportService = container.resolve('reportService')

reportService.getReport() // Report: data from DataService

Full TypeScript example with resolution, injection, scoping: docs/typescript-example.md

๐Ÿ”‹ APIs

Creates a new container.

createContainer(options?: ContainerOptions): Container

options.defaultStrategy : transient (default) - singleton

register

Registers multiple resolvers within the container.

container.register(entries: ResolverEntries): void

options.strategy : transient (default) - singleton

resolve

Injects a function or a class registered in the container with its dependencies and returns the result.

container.resolve<Key  extends keyof Container>(key: Key): Container[Key]

inject

Injects a function or a class not registered in the container with its dependencies and returns the result.

container.inject<T>(target: FunctionFactory<T>): T

createScope

Creates a new scope within the container.

container.createScope():  void

๐Ÿ“Š Comparisons

ConteneurJSInversifyJSTSyringeTypeDIAwilix
TS + ESM + Testsโœ…โœ…โœ…โœ…โœ…
Dependency Count๐Ÿฅ‡ 0๐Ÿฅˆ 1๐Ÿฅˆ 1๐Ÿฅ‡ 0๐Ÿฅ‰ 2
Runtime Agnosticโœ…โŒโŒโŒโŒ
Function Supportโœ…โŒโŒโŒโœ…
Class Supportโœ…โœ…โœ…โœ…โœ…
Value Supportโœ…โŒโŒโŒโœ…
Decorator Freeโœ…โŒโŒโŒโœ…
Lifetime Managementโœ…โœ…โœ…โœ…โœ…
Scoped Containerโœ…โœ…โœ…โŒโœ…
Size (min)๐Ÿฅ‡ 1.1kbโž– 49.9kbโž– 15.6kb๐Ÿฅˆ 9.5kb๐Ÿฅ‰ 12.5kb
Size (min + gzip)๐Ÿฅ‡ 0.6kbโž– 11.1kbโž– 4.7kb๐Ÿฅˆ 2.7kb๐Ÿฅ‰ 4.6kb

๐Ÿ“ƒ Inspiration

This project was inspired by jeffijoe/awilix and builds upon its core concepts.

2.1.2

4 months ago

2.1.1

9 months ago

2.1.0

9 months ago

2.0.1

10 months ago

2.0.0

10 months ago

1.1.0

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago