We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
The motivation for this issue was this comment.
I would like to implement the following:
HttpContext
The idea of HttpContext is based on ASP.NET and is a feature that allows the request and response to objects to be injected.
What should happen then is the following:
this._container.createChild()
TYPE.HttpContext
interface HttpContext { request: Request; response: Response; }
container.get
inRequestScope
Controller
This will add an extra bit to the previous workflow. What should happen then is the following:
AuthProvider
interface HttpContext { request: Request; response: Response; user: UserIdentity; }
BaseHttpController
We could also create a base controller instance that gets HttpContext injected by default so users will be able to do:
import * as express from "express"; import { interfaces, controller, httpGet, httpPost, httpDelete, request, queryParam, response, requestParam, BaseHttpController } from "inversify-express-utils"; import { injectable, inject } from "inversify"; @controller("/foo") @injectable() export class FooController extends BaseHttpController { @inject("FooService") private fooService: FooService; @httpGet("/") private index(): string { if (this.httpContext.user === undefined) { throw new Error(); } return this.fooService.get((this.httpContext.user.id); } }
authorize
We can document examples to implement a middleware that uses the HttpContext to validate if an user has access to certan feature:
@controller( "/foo", authorize({ feature: FEATURE.SOME_FEATURE_FLAG }), ) @injectable() export class FooController extends BaseHttpController { // ... }
Or validate if an user has access to certan role:
@controller( "/foo", authorize({ role: ROLE.SOME_ROLE }), ) @injectable() export class FooController extends BaseHttpController { // ... }
The community will then develop libraries for particular databases etc.
The text was updated successfully, but these errors were encountered:
I have implemented A, B and C inversify/inversify-express-utils#72 and I have moved D to a new issue #673
Sorry, something went wrong.
No branches or pull requests
The motivation for this issue was this comment.
I would like to implement the following:
A) Access to current request and response via
HttpContext
The idea of HttpContext is based on ASP.NET and is a feature that allows the request and response to objects to be injected.
What should happen then is the following:
this._container.createChild()
to prevent rare conditions.TYPE.HttpContext
and it includes current request and responsecontainer.get
is invoked.TYPE.HttpContext
is resolved usinginRequestScope
if the controller has a dependency on it.Controller
are resolved.TYPE.HttpContext
) are injected into deController
.B) Access to current user via
HttpContext
This will add an extra bit to the previous workflow. What should happen then is the following:
AuthProvider
before a request hits the server.this._container.createChild()
to prevent rare conditions.AuthProvider
if it is available (undefined by default).TYPE.HttpContext
and it includes current request, response, and usercontainer.get
is invoked.TYPE.HttpContext
is resolved usinginRequestScope
if the controller has a dependency on it.Controller
are resolved.TYPE.HttpContext
) are injected into deController
.C) Investigate support
BaseHttpController
to reduce boilerplateWe could also create a base controller instance that gets
HttpContext
injected by default so users will be able to do:D) Document
authorize
middleware usingHttpContext
We can document examples to implement a middleware that uses the
HttpContext
to validate if an user has access to certan feature:Or validate if an user has access to certan role:
The community will then develop libraries for particular databases etc.
The text was updated successfully, but these errors were encountered: