Comments (1)
same problem here:
import { Container, inject, injectable } from "inversify";
import "reflect-metadata";
@injectable()
class ModelA_inBoth {}
@injectable()
class ModelA2_inRoot {
@inject(ModelA_inBoth)
a1: ModelA_inBoth;
}
@injectable()
class ModelB_inRoot {
@inject(ModelA_inBoth)
a1: ModelA_inBoth;
}
@injectable()
class ModelC_inChild {
@inject(ModelA_inBoth)
a1: ModelA_inBoth;
@inject(ModelA2_inRoot)
a2: ModelA2_inRoot;
}
function test1() {
const root = new Container({ defaultScope: "Singleton" });
const child = root.createChild();
root.bind(ModelA_inBoth).toSelf();
root.bind(ModelA2_inRoot).toSelf(); // A2 -> A1
root.bind(ModelB_inRoot).toSelf(); // B -> A1
child.bind(ModelA_inBoth).toSelf();
child.bind(ModelC_inChild).toSelf(); // C -> A2 -> A1
const modelB = root.get(ModelB_inRoot); // root.B -> root.A1
const modelC = child.get(ModelC_inChild); // child.C -> root.A2 -> child.A1
// expect: child.C -> root.A2 -> root.A1
// actual: child.C -> root.A2 -> child.A1
// expect to be true, actual false
console.log(
"modelC.a2.a1 === modelB.a1, expect true",
modelC.a2.a1 === modelB.a1
);
// expect: child.C -> root.A1 === root.B -> root.A1
// actual: child.C -> child.A1 !== root.B -> root.A1
// expect to be true, actual false
console.log("modelC.a1 === modelB.a1, expect true", modelC.a1 === modelB.a1);
// expect: child.C -> child.A1 !== child.C -> root.A2 -> root.A1
// actual: child.C -> child.A1 === child.A -> root.A2 -> child.A1
// expect to be false, actual true
console.log(
"modelC.a1 === modelC.a2.a1, expect false",
modelC.a1 === modelC.a2.a1
);
}
test1();
The problem is, root.A2 -> child.A1, which violates the hierarchical relations between containers.
from inversifyjs.
Related Issues (20)
- regression: inversify 6 no longer allows binding null values HOT 3
- Support @singleton annotation HOT 2
- Inversify-generator: generator package for bindings and type identifiers
- Container takes a long time to instantiate HOT 1
- Tests for #549 are flaky (node 10 / es6) HOT 2
- TypeError: Converting circular structure to JSON HOT 1
- Remove `browser` test suite HOT 5
- container.onNoMatchingBindingsFount or .onError
- The error middleware throws unhandler error for first container config and last router
- How to inject method parameter HOT 1
- Last release was on Oct 14, 2021 HOT 8
- postConstruct inconsistency for sync and async
- Whether the inclusion size can be optimized
- Major bug, request scope in a singleton class is not working HOT 1
- Migrate to Monorepo HOT 2
- "TypeScript's constructor assignments" is not working HOT 2
- Decorator[@targetName] error TS1239: Unable to resolve signature of parameter decorator when called as an expression HOT 3
- Warn for mixing singleton with non-singleton scopes
- Option `skipBaseClassChecks` has no effect when inheritance is being used
- Moving from Symbol.for() to Symbol() doesn't resolve dependencies correctly HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from inversifyjs.