This commit is contained in:
nitowa
2022-07-25 04:06:21 +02:00
commit de0d8cfd8e
14 changed files with 1397 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
import { Singleton } from "../../src/Decorator";
import { COMPONENT_A_VALUE } from "../CONSTANTS";
@Singleton()
export class ComponentA{
private value: string
getFromThis(): string {
return this.value
}
initialize(): void{
this.value = COMPONENT_A_VALUE
}
}
+29
View File
@@ -0,0 +1,29 @@
import { Inject, Singleton } from "../../src/Decorator"
import { COMPONENT_B_VALUE } from "../CONSTANTS"
import { ComponentA } from "./ComponentA"
export abstract class IComponentB{
getFromA: () => string
getFromThis: () => string
}
@Singleton(IComponentB)
export class ComponentB implements IComponentB{
@Inject(ComponentA)
private componentA: ComponentA
private value: string
getFromA(): string {
return this.componentA.getFromThis()
}
getFromThis(): string {
return this.value
}
initialize(): void{
this.value = COMPONENT_B_VALUE
}
}
+22
View File
@@ -0,0 +1,22 @@
import { Injector } from '../../src/Injector'
import { TestComponent } from './TestComponent'
import { assert, expect } from 'chai';
import { COMPONENT_A_VALUE, COMPONENT_B_VALUE } from '../CONSTANTS';
var should = require('chai').should();
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
describe('dependjs', () => {
it('is able to resolve linear dependencies', () => {
const testComp = Injector.resolve(TestComponent)
expect(testComp.getFromA()).to.be.equal(COMPONENT_A_VALUE)
expect(testComp.getAThroughB()).to.be.equal(COMPONENT_A_VALUE)
expect(testComp.getFromB()).to.be.equal(COMPONENT_B_VALUE)
})
})
+26
View File
@@ -0,0 +1,26 @@
import { Inject, Singleton } from "../../src/Decorator";
import {ComponentA} from "./ComponentA"
import {IComponentB} from "./ComponentB"
@Singleton()
export class TestComponent{
@Inject(IComponentB)
private compoenntB: IComponentB
@Inject(ComponentA)
private componentA: ComponentA
getFromA(): string{
return this.componentA.getFromThis()
}
getAThroughB(): string{
return this.compoenntB.getFromA()
}
getFromB():string{
return this.compoenntB.getFromThis()
}
}
+2
View File
@@ -0,0 +1,2 @@
export const COMPONENT_A_VALUE = "ComponentA"
export const COMPONENT_B_VALUE = "ComponentB"