Skip to content
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

extend request or context to resolve nestjs providers #50

Open
Inoir opened this issue Jan 25, 2023 · 0 comments
Open

extend request or context to resolve nestjs providers #50

Inoir opened this issue Jan 25, 2023 · 0 comments

Comments

@Inoir
Copy link

Inoir commented Jan 25, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant