Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/newdash/inject
dependency inject container
https://github.com/newdash/inject
dependency-injection injection ioc typescript
Last synced: 5 days ago
JSON representation
dependency inject container
- Host: GitHub
- URL: https://github.com/newdash/inject
- Owner: newdash
- License: mit
- Created: 2020-08-18T09:21:51.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-05-28T08:28:33.000Z (7 months ago)
- Last Synced: 2024-05-29T19:45:41.996Z (7 months ago)
- Topics: dependency-injection, injection, ioc, typescript
- Language: TypeScript
- Homepage:
- Size: 1.48 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Dependency Inject Container
[![npm (scoped)](https://img.shields.io/npm/v/@newdash/inject?label=@newdash/inject)](https://www.npmjs.com/package/@newdash/inject)
[![Codecov](https://codecov.io/gh/newdash/inject/branch/master/graph/badge.svg)](https://codecov.io/gh/newdash/inject)
[![Netlify](https://img.shields.io/netlify/70db22cf-e923-4aa9-ac52-8591056c70f1?label=docs)](https://newdash-inject.netlify.fornever.org/)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=newdash_inject&metric=alert_status)](https://sonarcloud.io/dashboard?id=newdash_inject)
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=newdash_inject&metric=security_rating)](https://sonarcloud.io/dashboard?id=newdash_inject)Yet another `dependency injection` container for `typescript`
## Quick Start
```bash
# install libs
npm i -S reflect-metadata @newdash/inject
``````json5
// tsconfig.json
// remember enable decorator related flags
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true
}
}
``````ts
// import reflect lib firstly
import "reflect-metadata";
import { inject } from "@newdash/inject"// a really simple example
it('should support deep constructor injection', async () => {class A {
v: number
constructor(@inject("v") v) {
this.v = v;
}
}class B {
a: InjectWrappedInstance
constructor(@inject(A) a) {
this.a = a;
}
}const ic = InjectContainer.New();
ic.registerInstance("v", 999); // define an instance provider in simple way
const b = await ic.getInstance(B);
expect(b.a.v).toBe(999);});
```## [CHANGELOG](./CHANGELOG.md)
## [LICENSE](./LICENSE)