@univerjscoreclassesInjector

@univerjs/core v0.5.4


Class: Injector

Defined in: packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.17.0/node_modules/@wendellhu/redi/esm/injector.d.ts:9

Constructors

new Injector()

new Injector(dependencies?, parent?): Injector

Defined in: packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.17.0/node_modules/@wendellhu/redi/esm/injector.d.ts:22

Create a new Injector instance

Parameters

ParameterTypeDescription
dependencies?Dependency[]Dependencies that should be resolved by this injector instance.
parent?null | InjectorOptional parent injector.

Returns

Injector

Methods

add()

add<T>(dependency): void

Defined in: packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.17.0/node_modules/@wendellhu/redi/esm/injector.d.ts:50

Add a dependency or its instance into injector. It would throw an error if the dependency has already been instantiated.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
dependencyDependencyOrInstance<T>The dependency or an instance that would be add in the injector.

Returns

void


createChild()

createChild(dependencies?): Injector

Defined in: packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.17.0/node_modules/@wendellhu/redi/esm/injector.d.ts:38

Create a child inject with a set of dependencies.

Parameters

ParameterTypeDescription
dependencies?Dependency[]Dependencies that should be resolved by the newly created child injector.

Returns

Injector

The child injector.


createInstance()

createInstance<T, U, C>(ctor, ...customArgs): C

Defined in: packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.17.0/node_modules/@wendellhu/redi/esm/injector.d.ts:94

Instantiate a class. The created instance would not be held by the injector.

Type Parameters

Type Parameter
T extends unknown[]
U extends unknown[]
C

Parameters

ParameterType
ctor(…args) => C
customArgsT

Returns

C


delete()

delete<T>(identifier): void

Defined in: packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.17.0/node_modules/@wendellhu/redi/esm/injector.d.ts:64

Delete a dependency from an injector. It would throw an error when the deleted dependency has already been instantiated.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
identifierDependencyIdentifier<T>The identifier of the dependency that is supposed to be deleted.

Returns

void


dispose()

dispose(): void

Defined in: packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.17.0/node_modules/@wendellhu/redi/esm/injector.d.ts:42

Dispose the injector and all dependencies held by this injector. Note that its child injectors will dispose first.

Returns

void


get()

Call Signature

get<T>(id, lookUp?): T

Defined in: packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.17.0/node_modules/@wendellhu/redi/esm/injector.d.ts:80

Type Parameters
Type Parameter
T
Parameters
ParameterType
idDependencyIdentifier<T>
lookUp?LookUp
Returns

T

Call Signature

get<T>(
   id, 
   quantity, 
   lookUp?): T[]

Defined in: packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.17.0/node_modules/@wendellhu/redi/esm/injector.d.ts:81

Type Parameters
Type Parameter
T
Parameters
ParameterType
idDependencyIdentifier<T>
quantityMANY
lookUp?LookUp
Returns

T[]

Call Signature

get<T>(
   id, 
   quantity, 
   lookUp?): null | T

Defined in: packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.17.0/node_modules/@wendellhu/redi/esm/injector.d.ts:82

Type Parameters
Type Parameter
T
Parameters
ParameterType
idDependencyIdentifier<T>
quantityOPTIONAL
lookUp?LookUp
Returns

null | T

Call Signature

get<T>(
   id, 
   quantity, 
   lookUp?): T

Defined in: packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.17.0/node_modules/@wendellhu/redi/esm/injector.d.ts:83

Type Parameters
Type Parameter
T
Parameters
ParameterType
idDependencyIdentifier<T>
quantityREQUIRED
lookUp?LookUp
Returns

T

Call Signature

get<T>(
   id, 
   quantity?, 
   lookUp?): null | T | T[]

Defined in: packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.17.0/node_modules/@wendellhu/redi/esm/injector.d.ts:84

Type Parameters
Type Parameter
T
Parameters
ParameterType
idDependencyIdentifier<T>
quantity?Quantity
lookUp?LookUp
Returns

null | T | T[]

Call Signature

get<T>(
   id, 
   quantityOrLookup?, 
   lookUp?): null | T | T[]

Defined in: packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.17.0/node_modules/@wendellhu/redi/esm/injector.d.ts:85

Type Parameters
Type Parameter
T
Parameters
ParameterType
idDependencyIdentifier<T>
quantityOrLookup?| Quantity | LookUp
lookUp?LookUp
Returns

null | T | T[]


getAsync()

getAsync<T>(id): Promise<T>

Defined in: packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.17.0/node_modules/@wendellhu/redi/esm/injector.d.ts:90

Get a dependency in the async way.

Type Parameters

Type Parameter
T

Parameters

ParameterType
idDependencyIdentifier<T>

Returns

Promise<T>


has()

has<T>(id): boolean

Defined in: packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.17.0/node_modules/@wendellhu/redi/esm/injector.d.ts:79

Check if the injector could initialize a dependency.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
idDependencyIdentifier<T>Identifier of the dependency

Returns

boolean


invoke()

invoke<T, P>(cb, ...args): T

Defined in: packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.17.0/node_modules/@wendellhu/redi/esm/injector.d.ts:73

Invoke a function with dependencies injected. The function could only get dependency from the injector and other methods are not accessible for the function.

Type Parameters

Type ParameterDefault type
T-
P extends any[][]

Parameters

ParameterTypeDescription
cb(accessor, …args) => Tthe function to be executed
argsParguments to be passed into the function

Returns

T

the return value of the function


onDispose()

onDispose(callback): IDisposable

Defined in: packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.17.0/node_modules/@wendellhu/redi/esm/injector.d.ts:32

Add a callback function that will be triggered when the Injector is disposed. Please note that when you callback is invoked, the injector is already disposed and you will not be able to interact with this Injector any more.

Parameters

ParameterTypeDescription
callback() => voidThe callback function that will be invoked when the Injector is disposed.

Returns

IDisposable

A disposable that will remove the callback.


replace()

replace<T>(dependency): void

Defined in: packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.17.0/node_modules/@wendellhu/redi/esm/injector.d.ts:57

Replace an injection mapping for interface-based injection. It would throw an error if the dependency has already been instantiated.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
dependencyDependency<T>The dependency that will replace the already existed dependency.

Returns

void