Comparing version
@@ -1,7 +0,14 @@ | ||
import { Type } from './type'; | ||
import { AbstractType, Type } from './type'; | ||
import { InjectionToken } from './injection-token'; | ||
/** | ||
* 查找规则 | ||
*/ | ||
export declare enum InjectFlags { | ||
/** 默认查找规则 */ | ||
Default = "Default", | ||
/** 锁定当前容器 */ | ||
Self = "Self", | ||
/** 跳过当前容器 */ | ||
SkipSelf = "SkipSelf", | ||
/** 可选查找 */ | ||
Optional = "Optional" | ||
@@ -14,3 +21,3 @@ } | ||
abstract parentInjector: Injector; | ||
abstract get<T>(token: Type<T> | InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): T; | ||
abstract get<T>(token: Type<T> | AbstractType<T> | InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): T; | ||
} |
@@ -0,6 +1,13 @@ | ||
/** | ||
* 查找规则 | ||
*/ | ||
export var InjectFlags; | ||
(function (InjectFlags) { | ||
/** 默认查找规则 */ | ||
InjectFlags["Default"] = "Default"; | ||
/** 锁定当前容器 */ | ||
InjectFlags["Self"] = "Self"; | ||
/** 跳过当前容器 */ | ||
InjectFlags["SkipSelf"] = "SkipSelf"; | ||
/** 可选查找 */ | ||
InjectFlags["Optional"] = "Optional"; | ||
@@ -7,0 +14,0 @@ })(InjectFlags || (InjectFlags = {})); |
@@ -1,4 +0,5 @@ | ||
import { Type } from './type'; | ||
import { AbstractType, Type } from './type'; | ||
import { InjectionToken } from './injection-token'; | ||
export interface ClassProvider<T = any> { | ||
provide: any; | ||
provide: Type<T> | AbstractType<T> | InjectionToken<T>; | ||
useClass: Type<T>; | ||
@@ -8,3 +9,3 @@ deps?: any[]; | ||
export interface FactoryProvider<T = any> { | ||
provide: any; | ||
provide: Type<T> | AbstractType<T> | InjectionToken<T>; | ||
useFactory: (...args: any[]) => T; | ||
@@ -14,7 +15,7 @@ deps?: any[]; | ||
export interface ValueProvider<T = any> { | ||
provide: any; | ||
provide: Type<T> | AbstractType<T> | InjectionToken<T>; | ||
useValue: T; | ||
} | ||
export interface ExistingProvider<T = any> { | ||
provide: any; | ||
provide: Type<T> | AbstractType<T> | InjectionToken<T>; | ||
useExisting: T; | ||
@@ -28,3 +29,5 @@ } | ||
} | ||
export interface AbstractProvider<T = any> extends AbstractType<T> { | ||
} | ||
export declare type StaticProvider<T = any> = ClassProvider<T> | FactoryProvider<T> | ValueProvider<T> | ExistingProvider<T> | ConstructorProvider<T>; | ||
export declare type Provider<T = any> = TypeProvider<T> | ValueProvider<T> | ClassProvider<T> | ConstructorProvider<T> | ExistingProvider<T> | FactoryProvider<T>; | ||
export declare type Provider<T = any> = TypeProvider<T> | AbstractProvider<T> | StaticProvider<T>; |
import { Provider } from './provider'; | ||
import { InjectFlags, Injector } from './injector'; | ||
import { Type } from './type'; | ||
import { AbstractType, Type } from './type'; | ||
import { InjectionToken } from './injection-token'; | ||
@@ -22,3 +22,3 @@ import { Scope } from './injectable'; | ||
*/ | ||
get<T>(token: Type<T> | InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): T; | ||
get<T>(token: Type<T> | AbstractType<T> | InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): T; | ||
private getValue; | ||
@@ -25,0 +25,0 @@ /** |
import { InjectFlags, Injector } from './injector'; | ||
import { normalizeProvider } from './reflective-provider'; | ||
import { Self, SkipSelf } from './metadata'; | ||
import { madeProvideScopeError, makeInjectError } from './utils/inject-error'; | ||
import { makeProvideScopeError, makeInjectError } from './utils/inject-error'; | ||
import { ForwardRef } from './forward-ref'; | ||
@@ -11,3 +11,3 @@ import { InjectionToken } from './injection-token'; | ||
const reflectiveInjectorErrorFn = makeInjectError('ReflectiveInjectorError'); | ||
const provideScopeError = madeProvideScopeError('ReflectiveInjectorError'); | ||
const provideScopeError = makeProvideScopeError('ReflectiveInjectorError'); | ||
/** | ||
@@ -14,0 +14,0 @@ * 反射注入器 |
@@ -5,1 +5,4 @@ export declare const Type: FunctionConstructor; | ||
} | ||
export interface AbstractType<T> extends Function { | ||
prototype: T; | ||
} |
export declare function makeInjectError(name: string): (token: any) => Error; | ||
export declare function madeProvideScopeError(name: string): (token: any) => Error; | ||
export declare function makeProvideScopeError(name: string): (token: any) => Error; |
@@ -9,3 +9,3 @@ import { stringify } from './stringify'; | ||
} | ||
export function madeProvideScopeError(name) { | ||
export function makeProvideScopeError(name) { | ||
return function provideError(token) { | ||
@@ -12,0 +12,0 @@ const error = new Error(`Can not found provide scope \`${stringify(token)}\`!`); |
@@ -1,7 +0,14 @@ | ||
import { Type } from './type'; | ||
import { AbstractType, Type } from './type'; | ||
import { InjectionToken } from './injection-token'; | ||
/** | ||
* 查找规则 | ||
*/ | ||
export declare enum InjectFlags { | ||
/** 默认查找规则 */ | ||
Default = "Default", | ||
/** 锁定当前容器 */ | ||
Self = "Self", | ||
/** 跳过当前容器 */ | ||
SkipSelf = "SkipSelf", | ||
/** 可选查找 */ | ||
Optional = "Optional" | ||
@@ -14,3 +21,3 @@ } | ||
abstract parentInjector: Injector; | ||
abstract get<T>(token: Type<T> | InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): T; | ||
abstract get<T>(token: Type<T> | AbstractType<T> | InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): T; | ||
} |
@@ -13,7 +13,14 @@ (function (factory) { | ||
exports.Injector = exports.InjectFlags = void 0; | ||
/** | ||
* 查找规则 | ||
*/ | ||
var InjectFlags; | ||
(function (InjectFlags) { | ||
/** 默认查找规则 */ | ||
InjectFlags["Default"] = "Default"; | ||
/** 锁定当前容器 */ | ||
InjectFlags["Self"] = "Self"; | ||
/** 跳过当前容器 */ | ||
InjectFlags["SkipSelf"] = "SkipSelf"; | ||
/** 可选查找 */ | ||
InjectFlags["Optional"] = "Optional"; | ||
@@ -20,0 +27,0 @@ })(InjectFlags = exports.InjectFlags || (exports.InjectFlags = {})); |
@@ -1,4 +0,5 @@ | ||
import { Type } from './type'; | ||
import { AbstractType, Type } from './type'; | ||
import { InjectionToken } from './injection-token'; | ||
export interface ClassProvider<T = any> { | ||
provide: any; | ||
provide: Type<T> | AbstractType<T> | InjectionToken<T>; | ||
useClass: Type<T>; | ||
@@ -8,3 +9,3 @@ deps?: any[]; | ||
export interface FactoryProvider<T = any> { | ||
provide: any; | ||
provide: Type<T> | AbstractType<T> | InjectionToken<T>; | ||
useFactory: (...args: any[]) => T; | ||
@@ -14,7 +15,7 @@ deps?: any[]; | ||
export interface ValueProvider<T = any> { | ||
provide: any; | ||
provide: Type<T> | AbstractType<T> | InjectionToken<T>; | ||
useValue: T; | ||
} | ||
export interface ExistingProvider<T = any> { | ||
provide: any; | ||
provide: Type<T> | AbstractType<T> | InjectionToken<T>; | ||
useExisting: T; | ||
@@ -28,3 +29,5 @@ } | ||
} | ||
export interface AbstractProvider<T = any> extends AbstractType<T> { | ||
} | ||
export declare type StaticProvider<T = any> = ClassProvider<T> | FactoryProvider<T> | ValueProvider<T> | ExistingProvider<T> | ConstructorProvider<T>; | ||
export declare type Provider<T = any> = TypeProvider<T> | ValueProvider<T> | ClassProvider<T> | ConstructorProvider<T> | ExistingProvider<T> | FactoryProvider<T>; | ||
export declare type Provider<T = any> = TypeProvider<T> | AbstractProvider<T> | StaticProvider<T>; |
import { Provider } from './provider'; | ||
import { InjectFlags, Injector } from './injector'; | ||
import { Type } from './type'; | ||
import { AbstractType, Type } from './type'; | ||
import { InjectionToken } from './injection-token'; | ||
@@ -22,3 +22,3 @@ import { Scope } from './injectable'; | ||
*/ | ||
get<T>(token: Type<T> | InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): T; | ||
get<T>(token: Type<T> | AbstractType<T> | InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): T; | ||
private getValue; | ||
@@ -25,0 +25,0 @@ /** |
@@ -56,3 +56,3 @@ var __extends = (this && this.__extends) || (function () { | ||
var reflectiveInjectorErrorFn = inject_error_1.makeInjectError('ReflectiveInjectorError'); | ||
var provideScopeError = inject_error_1.madeProvideScopeError('ReflectiveInjectorError'); | ||
var provideScopeError = inject_error_1.makeProvideScopeError('ReflectiveInjectorError'); | ||
/** | ||
@@ -59,0 +59,0 @@ * 反射注入器 |
@@ -5,1 +5,4 @@ export declare const Type: FunctionConstructor; | ||
} | ||
export interface AbstractType<T> extends Function { | ||
prototype: T; | ||
} |
export declare function makeInjectError(name: string): (token: any) => Error; | ||
export declare function madeProvideScopeError(name: string): (token: any) => Error; | ||
export declare function makeProvideScopeError(name: string): (token: any) => Error; |
@@ -12,3 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.madeProvideScopeError = exports.makeInjectError = void 0; | ||
exports.makeProvideScopeError = exports.makeInjectError = void 0; | ||
var stringify_1 = require("./stringify"); | ||
@@ -23,3 +23,3 @@ function makeInjectError(name) { | ||
exports.makeInjectError = makeInjectError; | ||
function madeProvideScopeError(name) { | ||
function makeProvideScopeError(name) { | ||
return function provideError(token) { | ||
@@ -31,3 +31,3 @@ var error = new Error("Can not found provide scope `" + stringify_1.stringify(token) + "`!"); | ||
} | ||
exports.madeProvideScopeError = madeProvideScopeError; | ||
exports.makeProvideScopeError = makeProvideScopeError; | ||
}); |
{ | ||
"name": "@tanbo/di", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "A dependency injection Library", | ||
@@ -5,0 +5,0 @@ "main": "./bundles/umd/public-api.js", |
83124
1.68%2122
1.92%