loopbackio / loopback.io

LoopBack project site - now with documentation!
http://loopback.io
Other
264 stars 385 forks source link

Inject dependency into a class with other arguments #1636

Closed cw6365 closed 7 months ago

cw6365 commented 7 months ago

Ive had a look but cannot find the answer to this..

I have a class that takes two normal arguments, which works fine. I want to inject a provider into the constructor..

export class P12Signer extends Signer {
  options: any;
  cert: any;
  constructor(
    p12Buffer: any,
    additionalOptions = {},
    @inject(SigningBindings.TsaService)
    private readonly tsa: any,
  ) {
    super();

but when i do i get the following error..

src/services/encryption.service.ts:152:20 - error TS2554: Expected 3 arguments, but got 1.

152     const signer = new P12Signer(certificateBuffer);

I've tried inject it onto the attribute itself but it comes back as undefined. Whats the best way to do this? Thanks.

cw6365 commented 7 months ago

I injected it into the parent service and passed it as an argument, which worked but seems hacky. I'll close the issue so not to clog up the list, but would be good to know how it's done if someone sees this.