@tsed/di
Advanced tools
Comparing version 5.38.7 to 5.39.0
@@ -11,3 +11,3 @@ import { Store, Type } from "@tsed/core"; | ||
instance: T; | ||
deps: any[]; | ||
deps: TokenProvider[]; | ||
imports: any[]; | ||
@@ -14,0 +14,0 @@ useFactory: Function; |
@@ -13,2 +13,13 @@ import { IDIConfigurationOptions, ProviderScope, TokenProvider } from "../interfaces"; | ||
} | ||
export declare function Module({ imports, deps, root, scope, ...configuration }?: Partial<IModuleOptions>): Function; | ||
/** | ||
* Declare a new Ts.ED module | ||
* | ||
* ## Options | ||
* - imports: List of Provider which must be built by injector before invoking the module | ||
* - resolvers: List of external DI must be used to resolve unknown provider | ||
* - deps: List of provider must be injected to the module constructor (explicit declaration) | ||
* | ||
* @param options | ||
* @decorator | ||
*/ | ||
export declare function Module(options?: Partial<IModuleOptions>): Function; |
@@ -8,4 +8,15 @@ "use strict"; | ||
const injectable_1 = require("./injectable"); | ||
function Module(_a = {}) { | ||
var { imports, deps, root, scope } = _a, configuration = tslib_1.__rest(_a, ["imports", "deps", "root", "scope"]); | ||
/** | ||
* Declare a new Ts.ED module | ||
* | ||
* ## Options | ||
* - imports: List of Provider which must be built by injector before invoking the module | ||
* - resolvers: List of external DI must be used to resolve unknown provider | ||
* - deps: List of provider must be injected to the module constructor (explicit declaration) | ||
* | ||
* @param options | ||
* @decorator | ||
*/ | ||
function Module(options = {}) { | ||
const { imports, resolvers, deps, root, scope } = options, configuration = tslib_1.__rest(options, ["imports", "resolvers", "deps", "root", "scope"]); | ||
return core_1.applyDecorators(configuration_1.Configuration(configuration), injectable_1.Injectable({ | ||
@@ -17,2 +28,3 @@ type: interfaces_1.ProviderType.PROVIDER, | ||
injectable: false, | ||
resolvers, | ||
root | ||
@@ -19,0 +31,0 @@ })); |
@@ -0,1 +1,2 @@ | ||
import { IDIResolver } from "./IDIResolver"; | ||
import { ProviderScope } from "./ProviderScope"; | ||
@@ -12,3 +13,4 @@ declare global { | ||
}; | ||
resolvers?: IDIResolver[]; | ||
[key: string]: any; | ||
} |
export * from "./IDILogger"; | ||
export * from "./IDIConfigurationOptions"; | ||
export * from "./IDIResolver"; | ||
export * from "./IInjectableProperties"; | ||
@@ -4,0 +5,0 @@ export * from "./IInterceptor"; |
import { Type } from "@tsed/core"; | ||
import { IDIResolver } from "./IDIResolver"; | ||
import { ProviderScope } from "./ProviderScope"; | ||
@@ -46,2 +47,6 @@ import { ProviderType } from "./ProviderType"; | ||
/** | ||
* A list of resolvers which will be used to resolve missing Symbol/Class when injector invoke a Class. This property allow external DI usage. | ||
*/ | ||
resolvers?: IDIResolver[]; | ||
/** | ||
* | ||
@@ -48,0 +53,0 @@ */ |
@@ -5,2 +5,3 @@ import { Container } from "../class/Container"; | ||
import { IDIConfigurationOptions, IDILogger, IInjectablePropertyService, IInjectablePropertyValue, IInvokeOptions, ProviderScope, TokenProvider } from "../interfaces"; | ||
import { IDIResolver } from "../interfaces/IDIResolver"; | ||
import { DIConfiguration } from "./DIConfiguration"; | ||
@@ -34,2 +35,3 @@ /** | ||
logger: IDILogger; | ||
readonly resolvers: IDIResolver[]; | ||
private resolvedConfiguration; | ||
@@ -36,0 +38,0 @@ constructor(); |
@@ -46,2 +46,3 @@ "use strict"; | ||
this.logger = console; | ||
this.resolvers = []; | ||
this.resolvedConfiguration = false; | ||
@@ -233,2 +234,5 @@ const provider = this.addProvider(InjectorService_1).getProvider(InjectorService_1); | ||
} | ||
if (provider.resolvers) { | ||
this.resolvers.push(...provider.resolvers); | ||
} | ||
}); | ||
@@ -433,3 +437,14 @@ this.resolvedConfiguration = true; | ||
} | ||
const provider = this.hasProvider(token) ? this.getProvider(token) : new Provider_1.Provider(token); | ||
if (!this.hasProvider(token)) { | ||
// find | ||
const resolver = this.resolvers.find(resolver => { | ||
return resolver.get(token); | ||
}); | ||
const provider = new Provider_1.Provider(token); | ||
if (resolver) { | ||
provider.useFactory = () => resolver.get(token); | ||
} | ||
this.setProvider(token, provider); | ||
} | ||
const provider = this.getProvider(token); | ||
scope = scope || this.scopeOf(provider); | ||
@@ -436,0 +451,0 @@ deps = deps || provider.deps; |
{ | ||
"name": "@tsed/di", | ||
"version": "5.38.7", | ||
"version": "5.39.0", | ||
"description": "DI module for Ts.ED Framework", | ||
@@ -8,3 +8,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@tsed/core": "5.38.7", | ||
"@tsed/core": "5.39.0", | ||
"tslib": "1.10.0" | ||
@@ -11,0 +11,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
189037
122
2657
+ Added@tsed/core@5.39.0(transitive)
- Removed@tsed/core@5.38.7(transitive)
Updated@tsed/core@5.39.0