forwardRef
function 을 통해 순환 종속성을 해결할 수 있다.
ex) CatsService 와 CommonService 가 서로 참조할 경우
@Injectable()
export class CatsService {
constructor(
@Inject(forwardRef(() => CommonService))
private commonService: CommonService,
) {}
}
@Injectable()
export class CommonService {
constructor(
@Inject(forwardRef(() => CatsService))
private catsService: CatsService,
) {}
}
@Module({
imports: [forwardRef(() => CatsModule)],
})
export class CommonModule {}