Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tripolskypetr/di-kit
Minimal ioc container which allow circular dependency injection
https://github.com/tripolskypetr/di-kit
circular-dependencies circular-dependency dependency-injection ioc javascript nodejs typescript
Last synced: 14 days ago
JSON representation
Minimal ioc container which allow circular dependency injection
- Host: GitHub
- URL: https://github.com/tripolskypetr/di-kit
- Owner: tripolskypetr
- License: mit
- Created: 2024-08-12T11:43:52.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2024-08-25T10:50:23.000Z (3 months ago)
- Last Synced: 2024-10-10T19:29:22.548Z (about 1 month ago)
- Topics: circular-dependencies, circular-dependency, dependency-injection, ioc, javascript, nodejs, typescript
- Language: JavaScript
- Homepage: https://github.com/react-declarative/react-declarative
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# di-kit
> Minimal ioc container which allow circular dependency injection
## Installation
```bash
npm install di-kit
```## Code sample
```tsx
import { inject, provide, init } from './index.mjs';const TYPES = {
serviceFoo: Symbol('serviceFoo'),
serviceBar: Symbol('serviceBar'),
serviceBaz: Symbol('serviceBaz'),
};provide(
TYPES.serviceFoo,
() => new class {
bar = inject(TYPES.serviceBar);
}
);provide(
TYPES.serviceBar,
() => new class {
foo = inject(TYPES.serviceFoo);
baz = inject(TYPES.serviceBaz);
}
);provide(
TYPES.serviceBaz,
() => new class { }
);const ioc = {
serviceFoo: inject(TYPES.serviceFoo),
serviceBar: inject(TYPES.serviceBar),
serviceBaz: inject(TYPES.serviceBaz),
};init();
console.log(ioc.serviceFoo.bar.name);
console.log(ioc.serviceBar.foo.name);
console.log(ioc.serviceBar.baz.name);```