@alterior/di
Advanced tools
Comparing version 3.9.1 to 3.10.0
@@ -58,2 +58,9 @@ /** | ||
abstract get(token: any, notFoundValue?: any): any; | ||
/** | ||
* Run the given callback in an injection context for this injector. This allows you to use inject() within | ||
* arbitrary code. This only works synchronously (no async/await). | ||
* | ||
* @param callback The callback to run. | ||
*/ | ||
static run<T>(injector: Injector, callback: () => T): T; | ||
} | ||
@@ -60,0 +67,0 @@ /** |
@@ -43,9 +43,12 @@ /** | ||
/** | ||
* @internal | ||
* Run the given callback in an injection context for this injector. This allows you to use inject() within | ||
* arbitrary code. This only works synchronously (no async/await). | ||
* | ||
* @param callback The callback to run. | ||
*/ | ||
static _runInInjectionContext(injector, callback) { | ||
static run(injector, callback) { | ||
let previousContext = CURRENT_INJECTOR; | ||
CURRENT_INJECTOR = injector; | ||
try { | ||
callback(); | ||
return callback(); | ||
} | ||
@@ -52,0 +55,0 @@ finally { |
@@ -276,3 +276,3 @@ /** | ||
try { | ||
Injector._runInInjectionContext(this, () => { | ||
Injector.run(this, () => { | ||
obj = factory(...deps); | ||
@@ -279,0 +279,0 @@ }); |
@@ -58,2 +58,9 @@ /** | ||
abstract get(token: any, notFoundValue?: any): any; | ||
/** | ||
* Run the given callback in an injection context for this injector. This allows you to use inject() within | ||
* arbitrary code. This only works synchronously (no async/await). | ||
* | ||
* @param callback The callback to run. | ||
*/ | ||
static run<T>(injector: Injector, callback: () => T): T; | ||
} | ||
@@ -60,0 +67,0 @@ /** |
@@ -46,9 +46,12 @@ "use strict"; | ||
/** | ||
* @internal | ||
* Run the given callback in an injection context for this injector. This allows you to use inject() within | ||
* arbitrary code. This only works synchronously (no async/await). | ||
* | ||
* @param callback The callback to run. | ||
*/ | ||
static _runInInjectionContext(injector, callback) { | ||
static run(injector, callback) { | ||
let previousContext = CURRENT_INJECTOR; | ||
CURRENT_INJECTOR = injector; | ||
try { | ||
callback(); | ||
return callback(); | ||
} | ||
@@ -55,0 +58,0 @@ finally { |
@@ -280,3 +280,3 @@ "use strict"; | ||
try { | ||
injector_1.Injector._runInInjectionContext(this, () => { | ||
injector_1.Injector.run(this, () => { | ||
obj = factory(...deps); | ||
@@ -283,0 +283,0 @@ }); |
{ | ||
"name": "@alterior/di", | ||
"version": "3.9.1", | ||
"version": "3.10.0", | ||
"description": "Flexible reflection-based dependency injection", | ||
@@ -48,3 +48,3 @@ "author": "The Alterior Project (https://github.com/alterior-mvc)", | ||
}, | ||
"gitHead": "9d3a7885fb01f3a6f875d12bcdf1a8a7fca4ffc1" | ||
"gitHead": "aed6165703ffa9cf1319ed50578f18a300acdb9b" | ||
} |
@@ -81,9 +81,12 @@ /** | ||
/** | ||
* @internal | ||
* Run the given callback in an injection context for this injector. This allows you to use inject() within | ||
* arbitrary code. This only works synchronously (no async/await). | ||
* | ||
* @param callback The callback to run. | ||
*/ | ||
static _runInInjectionContext(injector: Injector, callback: () => void) { | ||
static run<T>(injector: Injector, callback: () => T) { | ||
let previousContext = CURRENT_INJECTOR; | ||
CURRENT_INJECTOR = injector; | ||
try { | ||
callback(); | ||
return callback(); | ||
} finally { | ||
@@ -95,2 +98,3 @@ CURRENT_INJECTOR = previousContext; | ||
/** | ||
@@ -97,0 +101,0 @@ * Type of the options argument to `inject`. |
@@ -450,3 +450,3 @@ /** | ||
try { | ||
Injector._runInInjectionContext(this, () => { | ||
Injector.run(this, () => { | ||
obj = factory(...deps); | ||
@@ -453,0 +453,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
702425
8652