# jsdicon

> Javascript Dependency Injection Container

Latest version **0.2.1** (published 2018-05-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install jsdicon
pnpm add jsdicon
yarn add jsdicon
bun add jsdicon
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2018-05-07 |
| First published | 2018-05-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Erzhan Torokulov |
| Maintainers | erzhtor |
| Keywords | vanilla, js, javascript, di, dependency, injection, container |

## Links

- npm: https://www.npmjs.com/package/jsdicon
- Repository: https://github.com/erzhtor/jsdicon
- Homepage: https://github.com/erzhtor/jsdicon#readme
- Issues: https://github.com/erzhtor/jsdicon/issues
- npm.io page: https://npm.io/package/jsdicon

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.2.1 (latest) — 2018-05-07
- 0.2.0 — 2018-05-07
- 0.1.1 — 2018-05-07
- 0.1.0 — 2018-05-07

## 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();
    ```

---
_Source: https://npm.io/package/jsdicon · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
