Skip to content

Commit

Permalink
fix(core): Making Request scope non durable win over scope durable
Browse files Browse the repository at this point in the history
If an instance has at least one dependency that is Request scope non durable, then the instance should be Request scope non durable itself.

Closes #10594
  • Loading branch information
vizio360 committed Dec 12, 2022
1 parent 1f4138b commit a4a8503
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
6 changes: 4 additions & 2 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
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 true', () => {
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 c', () => {
it('should return true', () => {
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

0 comments on commit a4a8503

Please sign in to comment.