Skip to content

Commit 665a12a

Browse files
committed
docs: update usage
1 parent 647cfd5 commit 665a12a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,37 @@
55
[![License](https://img.shields.io/github/license/x-profiler/injection)](LICENSE)
66

77
An IoC implemention for xprofiler.
8+
9+
## Usage
10+
11+
### Decorator
12+
13+
```ts
14+
import { Injectable, Inject } from "@xprofiler/injection";
15+
import { Config } from "./config";
16+
17+
@Injectable()
18+
export class Foo {
19+
@Inject()
20+
private config: Config;
21+
22+
getKmsConfig(@Inject('KMS_KEY') key: string) {
23+
return this.config[key];
24+
}
25+
}
26+
```
27+
28+
### Container
29+
30+
```ts
31+
import { Container } from "@xprofiler/injection";
32+
import { Foo, Bar } from "./items";
33+
34+
const container = new Container();
35+
36+
container.set(Foo);
37+
container.set(Bar);
38+
39+
const foo = container.get(Foo);
40+
const bar = container.get(Bar);
41+
```

0 commit comments

Comments
 (0)