-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic.ts
39 lines (31 loc) · 826 Bytes
/
basic.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Container } from "../mod.ts";
const container = new Container();
container.bind("logger", () => {
return {
log: (message: string) => console.log(message),
};
});
container.bind("service", (c: Container) => {
return {
log: (message: string) => c.resolve("logger").log(message),
};
});
const service: { log: (message: string) => void } = container.resolve("service");
service.log("Hello, world!");
container.resolve("service");
class LoggerService {
info(message: string) {
console.log(message);
}
error(message: string) {
console.error(message);
}
warn(message: string) {
console.warn(message);
}
debug(message: string) {
console.debug(message);
}
}
container.bind(LoggerService, () => new LoggerService());
container.resolve(LoggerService).info("Hello, World");