@univerjscoreclassesInjector

@univerjs/core v0.5.0-beta.1Docs


Class: Injector

Constructors

new Injector()

new Injector(dependencies?, parent?): Injector

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

Defined in

packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.16.1/node_modules/@wendellhu/redi/esm/injector.d.ts:23

Methods

add()

add<T>(dependency): void

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

Defined in

packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.16.1/node_modules/@wendellhu/redi/esm/injector.d.ts:41


createChild()

createChild(dependencies?): Injector

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.

Defined in

packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.16.1/node_modules/@wendellhu/redi/esm/injector.d.ts:29


createInstance()

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

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

Defined in

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


delete()

delete<T>(identifier): void

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

Defined in

packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.16.1/node_modules/@wendellhu/redi/esm/injector.d.ts:55


dispose()

dispose(): void

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

Returns

void

Defined in

packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.16.1/node_modules/@wendellhu/redi/esm/injector.d.ts:33


get()

get(id, lookUp)

get<T>(id, lookUp?): T
Type Parameters
Type Parameter
T
Parameters
ParameterType
idDependencyIdentifier<T>
lookUp?LookUp
Returns

T

Defined in

packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.16.1/node_modules/@wendellhu/redi/esm/injector.d.ts:71

get(id, quantity, lookUp)

get<T>(
   id, 
   quantity, 
   lookUp?): T[]
Type Parameters
Type Parameter
T
Parameters
ParameterType
idDependencyIdentifier<T>
quantityMANY
lookUp?LookUp
Returns

T[]

Defined in

packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.16.1/node_modules/@wendellhu/redi/esm/injector.d.ts:72

get(id, quantity, lookUp)

get<T>(
   id, 
   quantity, 
   lookUp?): null | T
Type Parameters
Type Parameter
T
Parameters
ParameterType
idDependencyIdentifier<T>
quantityOPTIONAL
lookUp?LookUp
Returns

null | T

Defined in

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

get(id, quantity, lookUp)

get<T>(
   id, 
   quantity, 
   lookUp?): T
Type Parameters
Type Parameter
T
Parameters
ParameterType
idDependencyIdentifier<T>
quantityREQUIRED
lookUp?LookUp
Returns

T

Defined in

packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.16.1/node_modules/@wendellhu/redi/esm/injector.d.ts:74

get(id, quantity, lookUp)

get<T>(
   id, 
   quantity?, 
   lookUp?): null | T | T[]
Type Parameters
Type Parameter
T
Parameters
ParameterType
idDependencyIdentifier<T>
quantity?Quantity
lookUp?LookUp
Returns

null | T | T[]

Defined in

packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.16.1/node_modules/@wendellhu/redi/esm/injector.d.ts:75

get(id, quantityOrLookup, lookUp)

get<T>(
   id, 
   quantityOrLookup?, 
   lookUp?): null | T | T[]
Type Parameters
Type Parameter
T
Parameters
ParameterType
idDependencyIdentifier<T>
quantityOrLookup?Quantity | LookUp
lookUp?LookUp
Returns

null | T | T[]

Defined in

packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.16.1/node_modules/@wendellhu/redi/esm/injector.d.ts:76


getAsync()

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

Get a dependency in the async way.

Type Parameters

Type Parameter
T

Parameters

ParameterType
idDependencyIdentifier<T>

Returns

Promise<T>

Defined in

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


has()

has<T>(id): boolean

Check if the injector could initialize a dependency.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
idDependencyIdentifier<T>Identifier of the dependency

Returns

boolean

Defined in

packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.16.1/node_modules/@wendellhu/redi/esm/injector.d.ts:70


invoke()

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

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

Defined in

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


replace()

replace<T>(dependency): void

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

Defined in

packages/api/tmp/univer-pro/node_modules/.pnpm/@wendellhu+redi@0.16.1/node_modules/@wendellhu/redi/esm/injector.d.ts:48