Skip to content

extend request or context to resolve nestjs providers #50

@Inoir

Description

@Inoir

currently its kinda impossible to resolve nestjs stuff inside i.e handler of actions. would be nice if this would be implemented.

my current workaround for this is to bind a moduleref on the current req obj inside the admin loader:

export class AdminLoader extends AbstractLoader {
  public constructor(private readonly moduleRef: ModuleRef) {
    super()
  }

  register(
    admin: AdminJS,
    httpAdapter: AbstractHttpAdapter<any, any, any>,
    options: AdminModuleOptions
  ) {
    .... lot other stuff

    app.use(options.adminJsOptions.rootPath, function admin(req, res, next) {
      req["resolver"] = moduleRef

      return router(req, res, next)
    })
   }
}

so on every request i can simply do:

const roleService = request.resolver.get(RoleService, {
  strict: false,
})

If there is already a way implemented, would be nice to point this out in the documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions