-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# NodeJS dependency injection in Angular style | ||
|
||
NodeJS dependency injection module on top of [inversify](http://inversify.io/) for using | ||
backend DI in a way similar to Angulars DI. E.g. you can use the following snippet throughout | ||
your complete application | ||
|
||
```typescript | ||
@FlModule({ | ||
imports: [ AuthModule, Http2Module ], | ||
declarations: [ AppComponent ], | ||
providers: [ AuthService ], | ||
exports: [ ] | ||
}) | ||
export class AppModule | ||
``` | ||
|
||
The other two decorators are | ||
|
||
```typescript | ||
@Component() | ||
export class AppComponent {} | ||
``` | ||
|
||
which treats the decorator as an inversify `@injectable` and directly creates an instance when the | ||
parent module gets instanciated. The other one is the `@Injectable()` decorator | ||
|
||
```typescript | ||
@Injectable() | ||
export class AuthService {} | ||
``` | ||
|
||
which returns an inversify `@injectable` decorator, but does not directly creates an instance but | ||
instanciates itself when an `@Inject(serviceIdentifier)` is used as a constructor parameter in the | ||
same or a childs containers class. | ||
|
||
The DI system is hierarchical. | ||
|
||
## Installation | ||
|
||
Add the package to your project | ||
|
||
```bash | ||
npm i --save fl-node-di | ||
# or | ||
yarn add fl-node-di | ||
``` | ||
|
||
Import the decorators with | ||
|
||
```typescript | ||
import { FlModule, Component, Injectable, Inject } from 'fl-node-di' | ||
``` | ||
|
||
## Dependencies | ||
|
||
- [inversify](http://inversify.io/) |