microsoft / microsoft/tsyringe
Could you add a little more sophisticated examples? (Also: Help me please!)
@Xapphire13 is already working on this.
Since Jul 9, 2020.
- Dominant language
- TypeScript
- Stars
- 6k
- Forks
- 184
- Avg merge
- 3m
- Merged PRs (30d)
- 1
Description
I am new to tsyringe (and DI) and have a really hard time to wrap my head around it. So I guess it would be of great help to have some more sophisticated examples in the readme?
E.g. my system looks like this, and I am stuck as of how to accomplish this in tsyringe:
A contains an array of B which contains C and D.
class C {
constructor(public parent:B){};
}
class D {
constructor(public myC:C){};
}
class B{
myC = new C(this);
myD = new D(this.myC)
}
class A {
myBs : B[]= [];
addB() {
this.myBs.push(new B())
}
}
A will need to pass some factory to A to add Bs, right?
And how do I prevent the container to instantiate a new C for D (but use the C from B)?
Same with C: how to I pass the reference to it's parent B (instead of instantiating a new B)?
Thank you for your time.
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.