Skip to content

Commit 03216d2

Browse files
bugfix(@nestjs/microservices) can't select/get from context
1 parent 2b29461 commit 03216d2

5 files changed

Lines changed: 14 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 4.6.4
2+
### Bug Fixes
3+
- **microservices**: can't select/get from context when using `NestFactory.createMicroservice` [#398](https://github.com/nestjs/nest/issues/398)
4+
15
## 4.6.3
26
### Bug Fixes
37
- **core**: error thrown when connecting to microservice (hybrid applicaton) [#425](https://github.com/nestjs/nest/issues/425)

lib/core/nest-application.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const iterare_1 = require("iterare");
1717
const logger_service_1 = require("@nestjs/common/services/logger.service");
1818
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
1919
const express_adapter_1 = require("./adapters/express-adapter");
20+
const application_config_1 = require("./application-config");
2021
const constants_1 = require("./constants");
2122
const middlewares_module_1 = require("./middlewares/middlewares-module");
2223
const routes_resolver_1 = require("./router/routes-resolver");
@@ -114,7 +115,8 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
114115
if (!NestMicroservice) {
115116
throw new microservices_package_not_found_exception_1.MicroservicesPackageNotFoundException();
116117
}
117-
const instance = new NestMicroservice(this.container, config);
118+
const applicationConfig = new application_config_1.ApplicationConfig();
119+
const instance = new NestMicroservice(this.container, config, applicationConfig);
118120
instance.setupListeners();
119121
instance.setIsInitialized(true);
120122
instance.setIsInitHookCalled(true);

src/core/nest-application-context.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ export class NestApplicationContext implements INestApplicationContext {
1414
protected contextModule,
1515
) {}
1616

17+
public selectContextModule() {
18+
const modules = this.container.getModules().values();
19+
this.contextModule = modules.next().value;
20+
}
21+
1722
public select<T>(module: Metatype<T>): INestApplicationContext {
1823
const modules = this.container.getModules();
1924
const moduleMetatype = this.contextModule.metatype;

src/core/nest-application.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ export class NestApplication extends NestApplicationContext
8282
);
8383
}
8484

85-
public selectContextModule() {
86-
const modules = this.container.getModules().values();
87-
this.contextModule = modules.next().value;
88-
}
89-
9085
public applyOptions() {
9186
if (!this.appOptions) {
9287
return undefined;

src/microservices/nest-microservice.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export class NestMicroservice extends NestApplicationContext
5858
this.server = strategy
5959
? strategy
6060
: ServerFactory.create(this.microserviceConfig);
61+
62+
this.selectContextModule();
6163
}
6264

6365
public setupModules() {

0 commit comments

Comments
 (0)