inversify-typesafe-spring-like 0.5.3 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +107 -1
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -24,4 +24,110 @@
24
24
  <a href="https://raw.githubusercontent.com/myeongjae-kim/inversify-typesafe/refs/heads/main/packages/inversify-typesafe-spring-like/LICENSE">
25
25
  <img src="https://img.shields.io/npm/l/inversify-typesafe-spring-like.svg" alt="MIT license" height="18">
26
26
  </a>
27
- </p>
27
+ </p>
28
+
29
+ ```ts
30
+ import { ApplicationContext, BeanConfig, returnAutowired } from "inversify-typesafe-spring-like";
31
+
32
+ interface Article {
33
+ id: number;
34
+ title: string;
35
+ content: string;
36
+ }
37
+
38
+ interface ArticleOutgoingPort {
39
+ getById(id: number): Promise<Article>
40
+ }
41
+
42
+ class ArticleRepository implements ArticleOutgoingPort {
43
+ getById(id: number): Promise<Article> {
44
+ return Promise.resolve({
45
+ id: id,
46
+ title: `title #${id}`,
47
+ content: `content #${id}`,
48
+ })
49
+ }
50
+ }
51
+
52
+ interface GetArticleUseCase {
53
+ execute(id: number): Promise<Article>
54
+ }
55
+
56
+ const { Autowired } = returnAutowired<Beans>();
57
+
58
+ class ArticleQueryService implements GetArticleUseCase {
59
+ constructor(
60
+ @Autowired("ArticleOutgoingPort") // compile error if a parameter of @Autowired is not a key of Beans.
61
+ private readonly articleOutgoingPort: ArticleOutgoingPort,
62
+ ) { }
63
+ execute(id: number): Promise<Article> {
64
+ return this.articleOutgoingPort.getById(id);
65
+ }
66
+ }
67
+
68
+ type Beans = {
69
+ GetArticleUseCase: GetArticleUseCase; // interface (class is also possible)
70
+ ArticleOutgoingPort: ArticleOutgoingPort; // interface (class is also possible)
71
+ }
72
+
73
+ const beanConfig: BeanConfig<Beans> = {
74
+ // compile error if ArticleQueryService is not compatible with GetArticleUseCase.
75
+ GetArticleUseCase: (bind) => bind().to(ArticleQueryService),
76
+ // compile error if ArticleRepository is not compatible with ArticleOutgoingPort.
77
+ ArticleOutgoingPort: (bind) => bind().to(ArticleRepository),
78
+ }
79
+
80
+ const applicationContext = ApplicationContext(beanConfig);
81
+
82
+ const getArticleUseCase = applicationContext.get("GetArticleUseCase")
83
+
84
+ getArticleUseCase.execute(1).then(console.log)
85
+ ```
86
+
87
+ ## Introduction
88
+
89
+ This library extends [inversify-typesafe](https://github.com/myeongjae-kim/inversify-typesafe) to provide a development experience similar to [Spring Framework](https://spring.io/).
90
+
91
+ It sets the default container scope to `Singleton` and exports standard `inversify-typesafe` utilities with Spring-like naming conventions, making it easier for developers familiar with Spring to adopt Inversify in TypeScript projects.
92
+
93
+ ## Installation
94
+
95
+ Via npm
96
+
97
+ ```bash
98
+ npm install inversify-typesafe-spring-like
99
+ ```
100
+
101
+ Via yarn
102
+
103
+ ```bash
104
+ yarn add inversify-typesafe-spring-like
105
+ ```
106
+
107
+ Via pnpm
108
+
109
+ ```bash
110
+ pnpm add inversify-typesafe-spring-like
111
+ ```
112
+
113
+ ## Demo
114
+
115
+ Try it out on <a href="https://stackblitz.com/edit/inversify-typesafe-spring-like?file=test%2Fmain.test.ts" target="_blank">StackBlitz</a>.
116
+
117
+ ## Types
118
+
119
+ https://inversify-typesafe-spring-like.myeongjae.kim/modules.html
120
+
121
+ ## Usage
122
+
123
+ The API is designed to mirror Spring's terminology:
124
+ 1. `createTypesafeContext()` $\rightarrow$ `ApplicationContext()`
125
+ - Note: `defaultScope` is set to `Singleton` by default.
126
+ 2. `returnTypesafeInject()` $\rightarrow$ `returnAutowired()`
127
+ 3. `TypesafeServiceConfig<T>` $\rightarrow$ `BeanConfig<T>`
128
+
129
+ For complete usage documentation and advanced features, please refer to the [inversify-typesafe documentation](https://github.com/myeongjae-kim/inversify-typesafe/tree/main?tab=readme-ov-file#usage).
130
+
131
+ ## License
132
+
133
+ MIT © [Myeongjae Kim](https://myeongjae.kim)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "inversify-typesafe-spring-like",
3
3
  "type": "module",
4
- "version": "0.5.3",
4
+ "version": "0.5.5",
5
5
  "description": "Add-On Library for inversify-typesafe to make it more like Spring.",
6
6
  "source": "src/index.ts",
7
7
  "exports": {
@@ -32,7 +32,7 @@
32
32
  "setup": "husky install",
33
33
  "clean": "rimraf dist",
34
34
  "bundle": "microbundle --format modern,cjs,umd",
35
- "typedoc": "typedoc src/index.ts --out docs/public/docs",
35
+ "typedoc": "typedoc src/index.ts --out docs/web/types",
36
36
  "build": "pnpm run clean && pnpm run bundle && sh ../../scripts/generate-cts.sh && rimraf dist/index.d.ts\\'\\'",
37
37
  "dev": "microbundle watch",
38
38
  "prepublishOnly": "pnpm run test && pnpm run build",
@@ -61,6 +61,6 @@
61
61
  "author": "Myeongjae Kim",
62
62
  "license": "MIT",
63
63
  "dependencies": {
64
- "inversify-typesafe": "^0.5.3"
64
+ "inversify-typesafe": "^0.5.4"
65
65
  }
66
66
  }