inversifyjs

How to support "per request" scope


I want to get the user token from the middlewares and injected into controller, is it possible?

class TaskController {
    @inject private currentUser

    @Post('/tasks')
    addTask() {
        if (!hasPermission(currentUser)) throw new Error("Unauthorized.")
        // ...
    }
}

I hope the injected currentUser above can be retrieved from some middlewares.


Solution

  • At the moment, InversifyJS onlysupports singleton and trainsient scopes. We have a roadmap item to investigate new types of scope.

    We are also working on the support for middleware at the moment but it is not fully ready. You can contact the development team on Gitter to find out more about our plans, help us or requests features.