@univerjs/core v0.5.0-beta.1 • Docs
Class: Injector
Constructors
new Injector()
new Injector(dependencies?, parent?): Injector
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
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
Parameter | Type | Description |
---|---|---|
dependency | DependencyOrInstance <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
Parameter | Type | Description |
---|---|---|
dependencies ? | Dependency [] | Dependencies that should be resolved by the newly created child injector. |
Returns
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
Parameter | Type |
---|---|
ctor | (…args ) => C |
…customArgs | T |
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
Parameter | Type | Description |
---|---|---|
identifier | DependencyIdentifier <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
Parameter | Type |
---|---|
id | DependencyIdentifier <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
Parameter | Type |
---|---|
id | DependencyIdentifier <T > |
quantity | MANY |
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
Parameter | Type |
---|---|
id | DependencyIdentifier <T > |
quantity | OPTIONAL |
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
Parameter | Type |
---|---|
id | DependencyIdentifier <T > |
quantity | REQUIRED |
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
Parameter | Type |
---|---|
id | DependencyIdentifier <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
Parameter | Type |
---|---|
id | DependencyIdentifier <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
Parameter | Type |
---|---|
id | DependencyIdentifier <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
Parameter | Type | Description |
---|---|---|
id | DependencyIdentifier <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 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
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
Parameter | Type | Description |
---|---|---|
dependency | Dependency <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