@furystack/inject
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -7,2 +7,3 @@ import { IDisposable } from "@sensenet/client-utils"; | ||
parent: Injector; | ||
owner: any; | ||
}; | ||
@@ -12,5 +13,5 @@ static Default: Injector; | ||
private cachedSingletons; | ||
GetInstance<T>(ctor: Constructable<T>, dependencies?: Array<Constructable<T>>): T; | ||
GetInstance<T>(ctor: Constructable<T>, local?: boolean, dependencies?: Array<Constructable<T>>): T; | ||
SetInstance<T>(instance: T, key?: Constructable<any>): void; | ||
constructor(options?: Partial<Injector["options"]>); | ||
} |
@@ -7,2 +7,3 @@ "use strict"; | ||
parent: Injector.Default, | ||
owner: null, | ||
}; | ||
@@ -23,3 +24,3 @@ this.meta = new Map(); | ||
} | ||
GetInstance(ctor, dependencies = []) { | ||
GetInstance(ctor, local = false, dependencies = []) { | ||
if (dependencies.includes(ctor)) { | ||
@@ -31,7 +32,7 @@ throw Error(`Circular dependencies found.`); | ||
} | ||
const fromParent = this.options.parent && this.options.parent.GetInstance(ctor); | ||
const fromParent = !local && this.options.parent && this.options.parent.GetInstance(ctor); | ||
if (fromParent) { | ||
return fromParent; | ||
} | ||
const deps = (this.meta.get(ctor) || []).map((dep) => this.GetInstance(dep, [...dependencies, ctor])); | ||
const deps = (this.meta.get(ctor) || []).map((dep) => this.GetInstance(dep, local, [...dependencies, ctor])); | ||
const newInstance = new ctor(...deps); | ||
@@ -38,0 +39,0 @@ this.SetInstance(newInstance); |
{ | ||
"name": "@furystack/inject", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Core FuryStack package", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -16,4 +16,5 @@ import { IDisposable } from "@sensenet/client-utils"; | ||
public options: { parent: Injector } = { | ||
public options: { parent: Injector, owner: any } = { | ||
parent: Injector.Default, | ||
owner: null, | ||
}; | ||
@@ -26,3 +27,3 @@ | ||
public GetInstance<T>(ctor: Constructable<T>, dependencies: Array<Constructable<T>> = []): T { | ||
public GetInstance<T>(ctor: Constructable<T>, local: boolean = false, dependencies: Array<Constructable<T>> = []): T { | ||
if (dependencies.includes(ctor)) { | ||
@@ -34,7 +35,7 @@ throw Error(`Circular dependencies found.`); | ||
} | ||
const fromParent = this.options.parent && this.options.parent.GetInstance(ctor); | ||
const fromParent = !local && this.options.parent && this.options.parent.GetInstance(ctor); | ||
if (fromParent) { | ||
return fromParent; | ||
} | ||
const deps = (this.meta.get(ctor) || []).map((dep) => this.GetInstance(dep, [...dependencies, ctor])); | ||
const deps = (this.meta.get(ctor) || []).map((dep) => this.GetInstance(dep, local, [...dependencies, ctor])); | ||
const newInstance = new ctor(...deps); | ||
@@ -41,0 +42,0 @@ this.SetInstance(newInstance); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29473
149