# flexi-container

> Flexible container for services that separates implementation and usage from configuration

Latest version **0.0.6** (published 2017-01-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install flexi-container
pnpm add flexi-container
yarn add flexi-container
bun add flexi-container
```

## 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.0.6 |
| Published | 2017-01-23 |
| First published | 2017-01-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Nadav Cohen |
| Maintainers | nyccyn |

## Links

- npm: https://www.npmjs.com/package/flexi-container
- Repository: https://github.com/nyccyn/flexi-container
- Homepage: https://github.com/nyccyn/flexi-container#readme
- Issues: https://github.com/nyccyn/flexi-container/issues
- npm.io page: https://npm.io/package/flexi-container

## Recent versions

- 0.0.6 (latest) — 2017-01-23
- 0.0.5 — 2017-01-19
- 0.0.4 — 2017-01-19
- 0.0.3 — 2017-01-19
- 0.0.2 — 2017-01-19
- 0.0.1 — 2017-01-19

## README

# flexi-container
Flexible container for services that separates implementation and usage from configuration.

flexi-container create services using provied plugin while the default plugin, ObjectContaier, create the service in memory.
### Supported Plugins
[flexi-container-socket](https://github.com/nyccyn/flexi-container-socket) - socket.io plugin

## Installion
`npm install --save flexi-container`

## Usage
Firts thing we need to create a `Contract` for our service that the service will implement and the consumer will use:
```javascript
// math-contract.js
const Contract = require('flexi-container').Contract;

module.exports = new Contract({
    add: Contract.Function,
    sub: Contract.Function
});
```

Contract's members can be either `Contract.Function` or `Contract.Event`.
When members is a `Contract.Event`, the method will be exposed to the concrete class.

our service just implement a class with the same members
```javascript
// math.js
class Math {
    add(a,b) {
        return a + b;
    }
    sub(a,b) {
        return a -b;
    }
}
```
to register the service in the container we'll call `registerService(contract, implementation, [plugin])` and to use the service a call `getService(contract, [plugin])`
```javascript
const flexiContainer = require('flexi-container');
const mathContract = require('./math-contract');
const Math = require('./math');

flexiContainer.registerService(mathContract, new Math());
const math = flexiContainer.getService(mathContract);

console.log(math.add(1,2));
console.log(math.sub(10,5));
```

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