Skip to content

Commit

Permalink
Start api reference section
Browse files Browse the repository at this point in the history
  • Loading branch information
betula committed Jun 26, 2019
1 parent 91fc1cf commit 180f408
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
Minimalistic Dependency Injection for Node.JS

- You can use it in any place of your application without rewrite your applications architecture or other preparations or initializations.
- Each dependency can be class, function, or any another value, and plain JavaScript object of cource too.
- You can override your dependencies for organize modules architecture, or unit testing without replace standart Node.JS require mechanism.
- Each dependency can be class, function, or any another value, and plain JavaScript object of course too.
- You can override your dependencies for organize modules architecture, or unit testing without hack standart Node.JS require mechanism.
- You can use TypeScript or JavaScript, with decorators or not.
- Defferent syntaxies for one mechanism. You can use constructor for provide dependencies or not, as you wish.
- You can create isolate context for multiple instances of you application with different set of depenencies, overrides and instances.
- You can create isolate context for multiple instances of you application (Dependency Injection scopes) with different set of depenencies, overrides and instances.

## Install

Expand Down Expand Up @@ -262,7 +262,7 @@ await b1Proxy.incAndPrint(); // Counter 2
await b2Proxy.incAndPrint(); // Counter 1
```

In each of `isolate` section you can define any overrides, scopes can be nested with inheris overrides.
In each of `isolate` section you can define any overrides, scopes can be nested with inherits overrides.

```JavaScript
// config.json
Expand Down Expand Up @@ -300,14 +300,41 @@ class Hello {

## API Reference

**inject**
**resolve**

**provide**
Returns instance of you dependency, or list of instances for dependencies. Each dependency can be class, function or any value.
- For class. Class will be instantiated onces and cached
- For function. Function will be called and result cached
- For any value. Return it value without any changes

**resolve**
```JavaScript
const depInstance = resolve(Dep);
const [ dep1, dep2, ... ] = resolve(Dep1, Dep2, ...);
```

**container**

Returns plain object with instantiated values. Each argument can be object of dependencies or result of previous `container` call. Result will be merged.

```JavaScript
const cont1 = container({ dep1: Dep1, dep2: Dep2 }, { dep3, Dep3 }, ...);
const cont2 = container({ dep4: Dep4 }, cont1, { dep5: Dep5 }, container({ dep6: Dep6 }, ...), ...);
const { dep1, dep2, dep3, dep4, dep5, dep6 } = cont2;
```

**inject**

Decorator for provide dependecies into object or class. If it run without arguments it use reflect metadata for determine list of dependencies from class constructor parameters.

```TypeScript
@inject // or @inject() its same
class {
constructor(public dep1: Dep1, public dep2: Dep2, ...) {}
}
```

**provide**

**attach**

**bind**
Expand Down

0 comments on commit 180f408

Please sign in to comment.