Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/erzhtor/jsdicon
Javascript Dependency Injection Container built using VanillaJS (without experimental decorators).
https://github.com/erzhtor/jsdicon
dependency-injection dependency-injection-container ioc-container vanilla-javascript vanilla-js
Last synced: about 1 month ago
JSON representation
Javascript Dependency Injection Container built using VanillaJS (without experimental decorators).
- Host: GitHub
- URL: https://github.com/erzhtor/jsdicon
- Owner: erzhtor
- Created: 2018-05-06T13:51:58.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-05-07T21:33:56.000Z (over 6 years ago)
- Last Synced: 2024-09-15T14:48:25.229Z (4 months ago)
- Topics: dependency-injection, dependency-injection-container, ioc-container, vanilla-javascript, vanilla-js
- Language: JavaScript
- Homepage:
- Size: 170 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Javascript Dependency Injection Container
[![Build Status](https://travis-ci.org/erzhtor/jsdicon.svg?branch=master)](https://travis-ci.org/erzhtor/jsdicon)
## API
* `inject` - wrap your functions\classes where you want to inject parameters
```js
// types.js
export const TYPE = Object.freeze({
foo: 'FOO_SERVICE',
bar: 'BAR_SERVICE',
appConfig: 'APP_CONFIG',
})// foo.js
import {inject} from 'jsdicon';
import {TYPE} from './types';export const foo = inject(TYPE.appConfig)(
function foo (appConfig) {
// do something with appConfig;
return someValue;
}
)// bar.js
import {inject} from 'jsdicon';
import {TYPE} from './types';export const Bar = inject(TYPE.foo, TYPE.appConfig)(
class Bar {
constructor(foo, appConfig) {
foo; // value of foo function is now available here
}startApp() {
}
// ... other properties and methods
}
)
```
* `Container` - create instance of **Container**
* `register` - registers class.
* `registerValue` - registers value.
* `registerFunc` - registers function
* `resolve` - resolve your type by typeId;
```js
// index.js
import {Container} from 'jsdicon';
import {TYPE} from './types';
import {foo} from './foo';
import {Bar} from './bar';const container = new Container();
container.register(TYPE.bar, Bar);
container.registerFunc(TYPE.foo, foo);
container.registerValue(TYPE.appConfig, {
ENV: 'DEV',
// ... other properties
});const bar = container.resolve(TYPE.bar);
bar.startApp();
```