Skip to content

Commit

Permalink
docs: update README
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed Mar 1, 2024
1 parent 329dfcd commit dd62cf1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
14 changes: 10 additions & 4 deletions README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ npm install @opensumi/di --save
yarn add @opensumi/di
```

将您的tsconfig.json修改为包含以下设置
将您的 tsconfig.json 修改为包含以下设置

```json
{
Expand All @@ -29,17 +29,17 @@ yarn add @opensumi/di
}
```

为Reflect API添加一个polyfill(下面的例子使用reflect-metadata)。你可以使用:
为 Reflect API 添加一个 polyfill(下面的例子使用 reflect-metadata)。你可以使用:

- [reflect-metadata](https://www.npmjs.com/package/reflect-metadata)
- [core-js (core-js/es7/reflect)](https://www.npmjs.com/package/core-js)
- [reflection](https://www.npmjs.com/package/@abraham/reflection)

Reflect polyfill的导入应该只添加一次,并且在使用DI之前
Reflect polyfill 的导入应该只添加一次,并且在使用 DI 之前

```typescript
// main.ts
import "reflect-metadata";
import 'reflect-metadata';

// 你的代码...
```
Expand Down Expand Up @@ -454,6 +454,12 @@ console.log(b.a instanceof A); // print 'true'

Whether have an instantiated object in the Injector.

### Injector.disposeOne / Injector.disposeAll

可以使用 `Injector.disposeOne``Injector.disposeAll` 来释放 Token。

这两个方法会从 DI 容器中删除当前已创建的实例,并尝试调用这个实例的 `dispose` 方法(可以没有)。

### markInjectable

```ts
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
[test-image]: https://codecov.io/gh/opensumi/di/branch/main/graph/badge.svg?token=07JAPLU957
[test-url]: https://codecov.io/gh/opensumi/di
[pkg-size]: https://pkg-size.dev/@opensumi/di
[pkg-size-img]: https://pkg-size.dev/badge/bundle/43685

> Inspired By [Angular](https://angular.io/guide/dependency-injection).
[pkg-size-img]: https://pkg-size.dev/badge/bundle/15776

This tool will help you achieve dependency inversion effectively without concerning the details of object instantiation. Additionally, since object instantiation is done within a registry, both the factory pattern and singleton pattern can be easily implemented.

Expand Down Expand Up @@ -56,7 +54,7 @@ The Reflect polyfill import should only be added once, and before DI is used:

```typescript
// main.ts
import "reflect-metadata";
import 'reflect-metadata';

// Your code here...
```
Expand Down Expand Up @@ -475,6 +473,12 @@ console.log(b.a instanceof A); // print 'true'

Whether have an instantiated object in the Injector.

### Injector.disposeOne / Injector.disposeAll

You can use `Injector.disposeOne` to dispose of a specific instance, and `Injector.disposeAll` to dispose of all instances.

These two methods will delete the instance from the Injector, and then call the `dispose` method of the instance if it exists.

### markInjectable

```ts
Expand Down

0 comments on commit dd62cf1

Please sign in to comment.