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
Parameter | Type | Description |
---|---|---|
dependencies ? | Dependency [] | Dependencies that should be resolved by this injector instance. |
parent ? | null | Injector | Optional parent injector. |
Returns
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
Parameter | Type | Description |
---|---|---|
dependency | DependencyOrInstance <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
Parameter | Type | Description |
---|---|---|
dependencies ? | Dependency [] | Dependencies that should be resolved by the newly created child injector. |
Returns
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
Parameter | Type |
---|---|
ctor | (…args ) => C |
…customArgs | T |
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
Parameter | Type | Description |
---|---|---|
identifier | DependencyIdentifier <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
Parameter | Type |
---|---|
id | DependencyIdentifier <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
Parameter | Type |
---|---|
id | DependencyIdentifier <T > |
quantity | MANY |
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
Parameter | Type |
---|---|
id | DependencyIdentifier <T > |
quantity | OPTIONAL |
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
Parameter | Type |
---|---|
id | DependencyIdentifier <T > |
quantity | REQUIRED |
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
Parameter | Type |
---|---|
id | DependencyIdentifier <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
Parameter | Type |
---|---|
id | DependencyIdentifier <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
Parameter | Type |
---|---|
id | DependencyIdentifier <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
Parameter | Type | Description |
---|---|---|
id | DependencyIdentifier <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 Parameter | Default type |
---|---|
T | - |
P extends any [] | [] |
Parameters
Parameter | Type | Description |
---|---|---|
cb | (accessor , …args ) => T | the function to be executed |
…args | P | arguments 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
Parameter | Type | Description |
---|---|---|
callback | () => void | The callback function that will be invoked when the Injector is disposed. |
Returns
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
Parameter | Type | Description |
---|---|---|
dependency | Dependency <T > | The dependency that will replace the already existed dependency. |
Returns
void