Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sota1235/closurebox
Simple DI container with flow
https://github.com/sota1235/closurebox
Last synced: about 12 hours ago
JSON representation
Simple DI container with flow
- Host: GitHub
- URL: https://github.com/sota1235/closurebox
- Owner: sota1235
- License: mit
- Created: 2017-06-24T16:47:22.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-06-25T14:29:16.000Z (over 7 years ago)
- Last Synced: 2024-10-14T09:27:42.978Z (23 days ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
ClosureBox
====[![npm version](https://badge.fury.io/js/closure-box.svg)](https://badge.fury.io/js/closure-box)
Simple DI container with flow for Node.js
### Description
Simple DI container with using flow.
### Requirement
You need to remove flow annotation with using [transform-flow-strip-types](https://babeljs.io/docs/plugins/transform-flow-strip-types/) plugin or [flow-remove-types](https://github.com/flowtype/flow-remove-types).
### Usage
Exported container is singleton instance.
Set instance.
```javascript
import UserRepository from 'repositories/user-repository';
import AuthService from 'services/auth-service';
import Container from 'closure-box';Container
.set('UserRepositoryInterface', () => {
return new UserRepository();
})
.set('services/auth-service', (container: type of Container) => {
return new AuthService(container.get('UserRepositoryInterface'));
});
```Get instance.
```javascript
import AuthService from 'services/auth-service';
import Container from 'closure-box';const authService: AuthService = Container.get('services/auth-service');
```Just it.
#### Strict mode
If you want to check type of instance, you can do it with enabling strict mode.
Firstly, please enable strict mode for Container instance.
```javascript
import Container from 'closure-box';Container.enableStrictMode();
```Secondly, pass boolean value when set instance into Container.
```javascript
import UserRepository from 'repositories/user-repository';
import Container from 'closure-box';Container
.set('repositories/user-repository', () => {
return new UserRepository();
}, true); // 3rd argument required
```Completed!
If you did it, Container check type of instance when **getting instance**.Container will compare instance obtained by registered function with instance obtained from key name.
### Install
```
yarn add closure-box
# or
npm i -S closure-box
```### Contribution
Please give me Pull Request :)
### Licence
This software is released under the MIT License, see LICENSE.txt.
## Author
[@sota1235](https://github.com/sota1235)