Skip to content

Commit

Permalink
feat(request_in_di): adding request insided DI
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien Ritz committed Nov 27, 2018
1 parent 23aac44 commit 3fe6f11
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ To set up your development environment:
[Back to top](#table-of-contents)

## Change History
* v1.6.0 (2018-11-27)
* Request in DI: Add request reference inside route DI
* v1.5.5 (2018-10-15)
* Boostrap fix: Exit the process if it fails
* v1.5.4 (2018-06-19)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hapiness/core",
"version": "1.5.5",
"version": "1.6.0",
"description": "Project to have a HapiJS (https://hapijs.com/) based framework to create easier NodeJS back-end with some awesome features",
"main": "commonjs/index.js",
"types": "index.d.ts",
Expand Down
10 changes: 8 additions & 2 deletions src/extensions/http-server/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CoreModule } from '../../core/interfaces';
import { CoreRoute } from './interfaces';
import { Observable } from 'rxjs';
import { Type } from '../../core/decorators';
import { Type, InjectionToken } from '../../core/decorators';
import { Route } from './decorators';
import { extractMetadataByDecorator } from '../../core/metadata';
import { DependencyInjection } from '../../core/di';
Expand All @@ -21,6 +21,8 @@ export class HttpRequestInfo {
id: string;
}

export const requestKey = new InjectionToken('request_key');

export class RouteBuilder {

/**
Expand Down Expand Up @@ -65,7 +67,11 @@ export class RouteBuilder {
id: request.id
}))
.map(_ => ({ provide: HttpRequestInfo, useValue: _ }))
.map(_ => [].concat(route.providers).concat(_))
.map(_ => []
.concat(route.providers)
.concat(_)
.concat({ provide: requestKey, useValue: request })
)
.flatMap(_ => DependencyInjection.createAndResolve(_, route.module.di))
.flatMap(_ => DependencyInjection.instantiateComponent(route.token, _));
}
Expand Down

0 comments on commit 3fe6f11

Please sign in to comment.