microsoft / microsoft/tsyringe
Child container doesn't auto inject from same container for ContainerScoped classes
Open
@Xapphire13 is already working on this.
Since Dec 6, 2019.
awaiting triage
- Dominant language
- TypeScript
- Stars
- 6k
- Forks
- 184
- Avg merge
- 3m
- Merged PRs (30d)
- 1
Description
Describe the bug
When using a child container, when resolving a class (with Lifecycle.ContainerScoped) its auto injected classes (also Lifecycle.ContainerScoped) are not taken from the child container.
To Reproduce
import { autoInjectable, container, Lifecycle, scoped } from "tsyringe";
@scoped(Lifecycle.ContainerScoped)
export class A {}
@scoped(Lifecycle.ContainerScoped)
@autoInjectable()
export class B {
constructor(public a: A) {}
}
const childContainer = container.createChildContainer();
const a = childContainer.resolve(A);
const b = childContainer.resolve(B);
console.log(a === b.a); // returns false, expecting true
Expected behavior
the auto injected class should be resolved from the same container
Version: 4.0.1
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.