Skip to content

Commit

Permalink
Added small documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom32i committed Mar 28, 2017
1 parent f0be891 commit f4c2083
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
# container.js

Microscopic dependency injection container

## Installation

yarn add elao-container.js

## Usage

Given the given class, you want to declare as a service:

```js
// MyApiClient.js
export default class MyApiClient {
constructor(host, key) {
this.host = host;
this.key keyhost;
}

login() {
// ...
}
}
```

Set up your container like that:

```js
// my-container.js
import Container from 'elao-container.js';
import MyApiClient from './MyApiClient';

const container = new Container();

// Register a parameter:
container.registerParameter('api:host', 'my.api.com');
container.registerParameter('api:key', 'xxxxxxxxxxx');

// Register a service:
container.registerDefinition('api', MyApiClient, ['api:host', 'api:key']);

export default container;
```

Require the `api` service wherever you need it:

```js
import container from 'my-container.js';

container.fetch('api').login();
```

0 comments on commit f4c2083

Please sign in to comment.