# bilstrap-iocjs

> IoC container for typescript and javascript

Latest version **1.1.0** (published 2022-04-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install bilstrap-iocjs
pnpm add bilstrap-iocjs
yarn add bilstrap-iocjs
bun add bilstrap-iocjs
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2022-04-30 |
| First published | 2019-12-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 15.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ajantha Bandara |
| Maintainers | ajanthab |
| Keywords | typescript |

## Links

- npm: https://www.npmjs.com/package/bilstrap-iocjs
- Repository: https://github.com/AjanthaB/bilstrap-iocjs
- Homepage: https://github.com/AjanthaB/bilstrap-iocjs#readme
- Issues: https://github.com/AjanthaB/bilstrap-iocjs/issues
- npm.io page: https://npm.io/package/bilstrap-iocjs

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2022-04-30
- 1.0.9 — 2020-01-09
- 1.0.6 — 2020-01-09
- 1.0.5 — 2019-12-25
- 1.0.4 — 2019-12-25
- 1.0.3 — 2019-12-25
- 1.0.2 — 2019-12-22
- 1.0.1 — 2019-12-22
- 1.0.0 — 2019-12-22

## README

# **Bilstrap-iocjs**

## Bilstrap-iocjs is a IoC(Inversion of Controll) container for your typescript project.

## Install

``` bash
npm install bilstrap-iosjs@latest
```

## This is a simple light weight typescript library that let you to remove your hardcodes dependencies from your ES6 classes. This allow you to manage both singleton and other dependency classes.

## Oldway

```ts
class Piston {
  constructor() {}

  public fire() {
    console.log('piston is firing')
  }
}

class Engine {
   constructor(private piston: Piston) {
     console.log('initializing Engine');
     // hardcodes value
     this.piston = new Piston();
   }

   public start() {
     console.log('Stating the engine');
     this.piston.fire();
   }

   public stop() {
     console.log('Stoping the engine');
   }
 }

 class Car {
   constructor(private engine: Engine) {
     // hardcoded values
     this.engine = new Engine(new Piston());
   }

   public start() {
     this.engine.start();
   }

   public getEngine(): Engine {
     return this.engine;
   }
 }
```

## Using bilstrap-iocjs

```ts
import { Container } from 'bilstrap-iocjs';

class Piston {
  constructor() {}

  public fire() {
    console.log('piston is firing')
  }
}

class Engine {
   constructor(private piston: Piston) {
     console.log('initializing Engine');
   }

   public start() {
     console.log('Stating the engine');
     this.piston.fire();
   }

   public stop() {
     console.log('Stoping the engine');
   }
 }

 class Car {
   // you dependencies define here
   constructor(private engine: Engine) {}

   public start() {
     this.engine.start();
   }

   public getEngine(): Engine {
     return this.engine;
   }
 }

const container = new Container();
// here you register the class
container.register('piston', Piston, []);
container.register('engine', Engine, ['piston']);
container.register('car', Car, ['engine']);

const BMW: any = container.get('car');
BMW.start();
```


## Singleton classes

```ts
// singleton example
container.register('piston', Piston, [], true);

 const BMW: any = container.get('car');
 const BENZ: any = container.get('car');
 BMW.start();
 BENZ.start();

 console.log('is same engine: ', BMW.getEngine() === BENZ.getEngine()) // false
 console.log('is same Piston: ', BMW.getEngine().getPiston() === BENZ.getEngine().getPiston()) // true

```

## Descorators

On the way


## Features

**register(uniqueClassName, BaseClass, Dependencies, singletonOrNot): void**

|          Prameter      |        Description                |
|------------------------|-----------------------------------|
| name : string          | unique name to identify the class |
| definition: Class      | Class that you want to register   |
| dependencies: string[] | string array of dependencies, these are unique names that you used to register the dependencies|
| isSingleton: boolean   | default value is **false**.       |

**get(name):an y**

| Parameter    | Description |
|--------------|-------------|
| name: string | unique name of the dependency you need

## Contribution

Become a contributor to this project. Feel free to submit an issue or a pull request.

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