Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Making Request scope non durable win over scope durable #10698

Merged
merged 2 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions packages/core/injector/instance-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,10 @@ export class InstanceWrapper<T = any> {
}
const isTreeNonDurable = this.introspectDepsAttribute(
(collection, registry) =>
collection.every(
(item: InstanceWrapper) => !item.isDependencyTreeDurable(registry),
collection.some(
(item: InstanceWrapper) =>
!item.isDependencyTreeStatic() &&
!item.isDependencyTreeDurable(registry),
),
lookupRegistry,
);
Expand Down Expand Up @@ -245,7 +247,13 @@ export class InstanceWrapper<T = any> {
}
const propertiesHosts = (properties || []).map(item => item.wrapper);
introspectionResult =
introspectionResult && callback(propertiesHosts, lookupRegistry);
introspectionResult &&
((properties &&
callback(
properties.map(item => item.wrapper),
lookupRegistry,
)) ||
!properties);
if (!introspectionResult || !enhancers) {
return introspectionResult;
}
Expand Down
48 changes: 48 additions & 0 deletions packages/core/test/injector/instance-wrapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,26 @@ describe('InstanceWrapper', () => {
expect(wrapper.isDependencyTreeDurable()).to.be.true;
});
});
describe('when one is not static, durable and non durable', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper();
wrapper.addCtorMetadata(0, new InstanceWrapper());
wrapper.addCtorMetadata(
1,
new InstanceWrapper({
scope: Scope.REQUEST,
durable: true,
}),
);
wrapper.addCtorMetadata(
2,
new InstanceWrapper({
scope: Scope.REQUEST,
}),
);
expect(wrapper.isDependencyTreeDurable()).to.be.false;
});
});
});
describe('properties', () => {
describe('when each is static', () => {
Expand Down Expand Up @@ -184,6 +204,21 @@ describe('InstanceWrapper', () => {
expect(wrapper.isDependencyTreeDurable()).to.be.true;
});
});
describe('when one is not static, non durable and durable', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper();
wrapper.addPropertiesMetadata(
'key1',
new InstanceWrapper({ scope: Scope.REQUEST, durable: true }),
);
wrapper.addPropertiesMetadata('key2', new InstanceWrapper());
wrapper.addPropertiesMetadata(
'key3',
new InstanceWrapper({ scope: Scope.REQUEST }),
);
expect(wrapper.isDependencyTreeDurable()).to.be.false;
});
});
});
describe('enhancers', () => {
describe('when each is static', () => {
Expand Down Expand Up @@ -214,6 +249,19 @@ describe('InstanceWrapper', () => {
expect(wrapper.isDependencyTreeDurable()).to.be.true;
});
});
describe('when one is not static, non durable and durable', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper();
wrapper.addEnhancerMetadata(
new InstanceWrapper({ scope: Scope.REQUEST, durable: true }),
);
wrapper.addEnhancerMetadata(new InstanceWrapper());
wrapper.addEnhancerMetadata(
new InstanceWrapper({ scope: Scope.REQUEST }),
);
expect(wrapper.isDependencyTreeDurable()).to.be.false;
});
});
});
});
});
Expand Down