microsoft / microsoft/tsyringe

Child container doesn't auto inject from same container for ContainerScoped classes

Open
#65 7 comments 1 reaction 1 assignee View on GitHub

@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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.