Skip to content

Commit

Permalink
refactor(core): extract get context id logic into its own method
Browse files Browse the repository at this point in the history
  • Loading branch information
micalevisk committed Jan 6, 2023
1 parent dda7ded commit 637ceed
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions packages/core/middleware/middleware-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,23 +212,7 @@ export class MiddlewareModule {
next: () => void,
) => {
try {
const contextId = ContextIdFactory.getByRequest(req);
if (!req[REQUEST_CONTEXT_ID]) {
Object.defineProperty(req, REQUEST_CONTEXT_ID, {
value: contextId,
enumerable: false,
writable: false,
configurable: false,
});

const requestProviderValue = isTreeDurable
? contextId.payload
: req;
this.container.registerRequestProvider(
requestProviderValue,
contextId,
);
}
const contextId = this.getContextId(req, isTreeDurable);
const contextInstance = await this.injector.loadPerContext(
instance,
moduleRef,
Expand Down Expand Up @@ -325,4 +309,20 @@ export class MiddlewareModule {
},
);
}

private getContextId(request: unknown, isTreeDurable: boolean): ContextId {
const contextId = ContextIdFactory.getByRequest(request);
if (!request[REQUEST_CONTEXT_ID]) {
Object.defineProperty(request, REQUEST_CONTEXT_ID, {
value: contextId,
enumerable: false,
writable: false,
configurable: false,
});

const requestProviderValue = isTreeDurable ? contextId.payload : request;
this.container.registerRequestProvider(requestProviderValue, contextId);
}
return contextId;
}
}

0 comments on commit 637ceed

Please sign in to comment.