Skip to content

Commit

Permalink
bugfix(@nestjs/microservices) can't select/get from context
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Feb 16, 2018
1 parent 2b29461 commit 03216d2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.6.4
### Bug Fixes
- **microservices**: can't select/get from context when using `NestFactory.createMicroservice` [#398](https://github.com/nestjs/nest/issues/398)

## 4.6.3
### Bug Fixes
- **core**: error thrown when connecting to microservice (hybrid applicaton) [#425](https://github.com/nestjs/nest/issues/425)
Expand Down
4 changes: 3 additions & 1 deletion lib/core/nest-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const iterare_1 = require("iterare");
const logger_service_1 = require("@nestjs/common/services/logger.service");
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
const express_adapter_1 = require("./adapters/express-adapter");
const application_config_1 = require("./application-config");
const constants_1 = require("./constants");
const middlewares_module_1 = require("./middlewares/middlewares-module");
const routes_resolver_1 = require("./router/routes-resolver");
Expand Down Expand Up @@ -114,7 +115,8 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
if (!NestMicroservice) {
throw new microservices_package_not_found_exception_1.MicroservicesPackageNotFoundException();
}
const instance = new NestMicroservice(this.container, config);
const applicationConfig = new application_config_1.ApplicationConfig();
const instance = new NestMicroservice(this.container, config, applicationConfig);
instance.setupListeners();
instance.setIsInitialized(true);
instance.setIsInitHookCalled(true);
Expand Down
5 changes: 5 additions & 0 deletions src/core/nest-application-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export class NestApplicationContext implements INestApplicationContext {
protected contextModule,
) {}

public selectContextModule() {
const modules = this.container.getModules().values();
this.contextModule = modules.next().value;
}

public select<T>(module: Metatype<T>): INestApplicationContext {
const modules = this.container.getModules();
const moduleMetatype = this.contextModule.metatype;
Expand Down
5 changes: 0 additions & 5 deletions src/core/nest-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ export class NestApplication extends NestApplicationContext
);
}

public selectContextModule() {
const modules = this.container.getModules().values();
this.contextModule = modules.next().value;
}

public applyOptions() {
if (!this.appOptions) {
return undefined;
Expand Down
2 changes: 2 additions & 0 deletions src/microservices/nest-microservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export class NestMicroservice extends NestApplicationContext
this.server = strategy
? strategy
: ServerFactory.create(this.microserviceConfig);

this.selectContextModule();
}

public setupModules() {
Expand Down

0 comments on commit 03216d2

Please sign in to comment.