-
Notifications
You must be signed in to change notification settings - Fork 166
Closed
Labels
status: awaiting answerAwaiting answer from the author of issue or PR.Awaiting answer from the author of issue or PR.
Description
Hei, i'm experiencing weird behaviour in my tests with constructor injects
//..
import {Container} from 'typedi';
import {AccessTokenService} from 'src/authentication/services/access-token-service';
import * as cfg from 'src/application/config';
Container.set('cfg.auth.jwt',cfg.auth.jwt);
const accessTokenService = Container.get(AccessTokenService);
accessTokenService.makeAccessToken(user);
//..Dependecies are undefined when i configure them in the constructor
import {Service, Inject, Require} from 'typedi';
// ..
@Service('AccessTokenService')
export class AccessTokenService {
constructor(
@Require('moment') private moment,
@Require('jsonwebtoken') private jsonwebtoken,
@Inject('cfg.auth.jwt') private jwt
) {}
makeAccessToken(user: User) {
console.log(typeof this.jsonwebtoken); //undefined
console.log(typeof this.jwt); //undefined
console.log(typeof this.moment); //undefined
// ...
}
}But this works
import {Service, Inject, Require} from 'typedi';
// ..
@Service('AccessTokenService')
export class AccessTokenService {
@Require('moment') private moment;
@Require('jsonwebtoken') private jsonwebtoken;
@Inject('cfg.auth.jwt') private jwt;
makeAccessToken(user: User) {
console.log(typeof this.jsonwebtoken); //object
console.log(typeof this.jwt); //object
console.log(typeof this.moment); //function
// ...
}
}Metadata
Metadata
Assignees
Labels
status: awaiting answerAwaiting answer from the author of issue or PR.Awaiting answer from the author of issue or PR.