Skip to content

Pass action to container.get #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ You can use routing-controllers with [express.js][1] or [koa.js][2].

1. Install module:

`npm install routing-controllers --save`
`npm install routing-controllers class-validator --save`

2. `reflect-metadata` shim is required:

Expand Down Expand Up @@ -1359,6 +1359,39 @@ export class UsersController {
}
```

For other IoC providers that don't expose a `get(xxx)` function, you can create an IoC adapter using `IocAdapter` like so:

```typescript
// inversify-adapter.ts
import { IoCAdapter } from 'routing-controllers'
import { Container } from 'inversify'

class InversifyAdapter implements IocAdapter {
constructor (
private readonly container: Container
) {
}

get<T> (someClass: ClassConstructor<T>, action?: Action): T {
const childContainer = this.container.createChild()
childContainer.bind(API_SYMBOLS.ClientIp).toConstantValue(action.context.ip)
return childContainer.resolve<T>(someClass)
}
}
```

And then tell Routing Controllers to use it:
```typescript
// Somewhere in your app startup
import { useContainer } from 'routing-controllers'
import { Container } from 'inversify'
import { InversifyAdapter } from './inversify-adapter.ts'

const container = new Container()
const inversifyAdapter = new InversifyAdapter(container)
useContainer(inversifyAdapter)
```

## Custom parameter decorators

You can create your own parameter decorators.
Expand Down
Loading