Refactoring nestJS circular dependency on modules without using forwardRef

Viewed 19

In this github issue author uses process nextTick to solve the issue. But it is not recommended. You can fix this issue using the the process.nextTick() function:

async getUsers() {
    await new Promise(resolve => process.nextTick(resolve)); // <- add this
    console.log('getUsers function');
    ...
}

Still, using request-scoped providers in combination with circular dependencies is very unpredictable and I'd strongly recommend refactoring your code to get rid of them.

My Case is like the below:

AppLogModule imports AppDeployment -> AppLogService has multiple methods that use appdeploymentService.

Now AppDeploymentService wants to use appLogservice through importing the AppLogsModule. Only 1 method uses applogService in appDeploymentservice.

0 Answers
Related