Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/unlight/inject
Inject a dependency (service locator pattern)
https://github.com/unlight/inject
dependency-injection inject injector service-locator
Last synced: 6 days ago
JSON representation
Inject a dependency (service locator pattern)
- Host: GitHub
- URL: https://github.com/unlight/inject
- Owner: unlight
- License: mit
- Created: 2017-03-07T12:56:53.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-02-07T05:51:13.000Z (9 months ago)
- Last Synced: 2024-10-05T11:34:56.042Z (about 1 month ago)
- Topics: dependency-injection, inject, injector, service-locator
- Language: TypeScript
- Homepage:
- Size: 239 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# inject
Inject a dependency (service locator pattern).
## USAGE
```ts
// app.ts
import { inject } from 'njct';
const fs = inject('fs', () => require('fs'));
fs.readFileSync('data.json');// app.spec.ts
import { injector } from 'njct';
injector.provide('fs', () => ({
readFileSync: () => 'result of call of fs.readFileSync()',
}));
``````ts
class Car {
static count = 0;
constructor() {
Car.count++;
}
}
let vehicle = inject(Car);
vehicle = inject(Car);
expect(vehicle).toBeA(Car);
expect(Car.count).toEqual(1);
```## Similar Projects
- https://github.com/mickgrz/injects
## License
[MIT License](https://opensource.org/licenses/MIT) (c) 2022