Skip to content

[inversify-express-utils] http request scope doesn't seem to be working as documented #431

@xenoterracide

Description

@xenoterracide

When I try to call the autofactory it says the service doesn't exist, if I don't use an autofactory it says the same thing but on parent service creation.

also interfaces.Autofactory doesn't exist. At the very least the documentation needs to improve to be correct. Ideally using something more complex than injecting a string.

Current Behavior

[back-end] [1652813224152] ERROR (CommentController/98837 on 5c52309d33e3): viewComments No matching bindings found for serviceIdentifier: ServiceNowUserByEidDataLoader

Steps to Reproduce (for bugs)

hopefully this is unambiguous and reproduceable

import e from 'express'
import { injectable } from 'inversify'
import { BaseMiddleware } from 'inversify-express-utils'

import { ServiceNowUserByEidDataLoader } from './service-now-user-by-eid-data-loader'

@injectable()
export class DataLoaderMiddleware extends BaseMiddleware {
  handler(req: e.Request, res: e.Response, next: e.NextFunction): void {
    this.bind(ServiceNowUserByEidDataLoader).toSelf().inSingletonScope()
    next()
  }
}

root container

container.bind(TYPES.UserInfoByEid).toAutoFactory(ServiceNowUserByEidDataLoader)
container.bind(DataLoaderMiddleware).toSelf()
  UserInfoByEid: Symbol.for('Factory<ServiceNowUserByEidDataLoader>'),

documentation suggests that you should use interfaces.Autofactory but we don't have that

@injectable()
export class UserService {
  private readonly log = LogProvider.getLogger()

  constructor(
    @inject(TYPES.UserInfoByEid)
    private readonly snUserDataLoader: () => ServiceNowUserByEidDataLoader
    )

... some method
    const dl = this.snUserDataLoader()

 @injectable()
export class ServiceNowUserByEidDataLoader extends AbstractDataLoader<ServiceNowUser> {

Your Environment

❯ uname -a && node --version && npm explain inversify inversify-express-utils
Darwin 5c52309d33e3 20.6.0 Darwin Kernel Version 20.6.0: Tue Feb 22 21:10:41 PST 2022; root:xnu-7195.141.26~1/RELEASE_X86_64 x86_64 i386 MacBookPro16,1 Darwin
v16.14.2
[email protected]
node_modules/inversify
  inversify@"^5.1.1" from [email protected]
  back-end
    [email protected]
    node_modules/back-end
      workspace back-end from the root project

[email protected]
node_modules/inversify-express-utils
  inversify-express-utils@"^6.3.2" from [email protected]
  back-end
    [email protected]
    node_modules/back-end
      workspace back-end from the root project

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions