inversify 7.0.0-alpha.2 β 7.0.0-alpha.3
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.
- package/CHANGELOG.md +5 -0
- package/README.md +3 -230
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,11 @@ All notable changes to this project from 5.0.0 forward will be documented in thi
|
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [7.0.0-alpha.3]
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
- Updated `BindToFluentSyntax` with `.toResolvedValue`.
|
|
11
|
+
|
|
7
12
|
## [7.0.0-alpha.2]
|
|
8
13
|
|
|
9
14
|
### Changed
|
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ InversifyJS has been developed with 4 main goals:
|
|
|
40
40
|
|
|
41
41
|
3. Add as little runtime overhead as possible.
|
|
42
42
|
|
|
43
|
-
4. Provide a
|
|
43
|
+
4. Provide a state of the art development experience.
|
|
44
44
|
|
|
45
45
|
## Testimonies
|
|
46
46
|
|
|
@@ -56,235 +56,8 @@ InversifyJS has been developed with 4 main goals:
|
|
|
56
56
|
|
|
57
57
|
[<img src="https://avatars0.githubusercontent.com/u/6154722?s=200&v=4" width="100" />](https://opensource.microsoft.com/)[<img src="https://avatars2.githubusercontent.com/u/69631?s=200&v=4" width="100" />](https://code.facebook.com/projects/1021334114569758/nuclide/)[<img src="https://avatars0.githubusercontent.com/u/2232217?s=200&v=4" width="100" />](https://aws.github.io/aws-amplify/)[<img src="https://avatars0.githubusercontent.com/u/1520648?s=200&v=4" width="100" />](https://www.plainconcepts.com/)[<img src="https://avatars3.githubusercontent.com/u/6962987?s=200&v=4" width="100" />](https://api.slack.com/)[<img src="https://pbs.twimg.com/profile_images/827249559046909954/SyaBPcH8_400x400.jpg" width="100" />](http://acia.aon.com/index.php/home/) [<img src="https://avatars3.githubusercontent.com/u/114767?s=200&v=4" width="100" />](https://www.lonelyplanet.com/) [<img src="https://avatars0.githubusercontent.com/u/25283328?s=200&v=4" width="100" />](https://jincor.com/) [<img src="https://avatars1.githubusercontent.com/u/1957282?s=200&v=4" width="100" />](https://www.web-computing.de/) [<img src="https://avatars1.githubusercontent.com/u/17648048?s=200&v=4" width="100" />](https://dcos.io/) [<img src="https://avatars0.githubusercontent.com/u/16970371?s=200&v=4" width="100" />](https://typefox.io/) [<img src="https://avatars0.githubusercontent.com/u/18010308?s=200&v=4" width="100" />](https://code4.ro/) [<img src="https://user-images.githubusercontent.com/10656223/33888109-fae0852e-df43-11e7-97f6-9db543da0bde.png" width="100">](http://www.baidu.com/) [<img src="https://avatars2.githubusercontent.com/u/8085382?s=200&v=4" width="100" />](https://www.imdada.cn/) [<img src="https://avatars2.githubusercontent.com/u/17041151?s=200&v=4" width="100" />](https://www.ato.gov.au/) [<img src="https://avatars1.githubusercontent.com/u/14963540?s=200&v=4" width="100" />](https://www.kaneoh.com/) [<img src="https://avatars0.githubusercontent.com/u/26021686?s=200&v=4" width="100" />](https://particl.io/) [<img src="https://avatars2.githubusercontent.com/u/24523195?s=200&v=4" width="100" />](https://slackmap.com/) [<img src="https://avatars3.githubusercontent.com/u/16556899?s=200&v=4" width="100" />](https://www.go1.com/) [<img src="https://avatars3.githubusercontent.com/u/23475730?s=200&v=4" width="100" />](http://www.stellwagengroup.com/stellwagen-technology/) [<img src="https://avatars1.githubusercontent.com/u/15262567?s=200&v=4" width="100" />](https://www.edrlab.org/) [<img src="https://avatars1.githubusercontent.com/u/10072104?s=200&v=4" width="100" />](https://www.goodgamestudios.com/) [<img src="https://avatars2.githubusercontent.com/u/13613760?s=200&v=4" width="100" />](https://freshfox.at/) [<img src="https://avatars1.githubusercontent.com/u/864482?s=200&v=4" width="100" />](https://schubergphilis.com/)
|
|
58
58
|
|
|
59
|
-
##
|
|
60
|
-
|
|
61
|
-
You can get the latest release and the type definitions using your preferred package manager:
|
|
62
|
-
|
|
63
|
-
```sh
|
|
64
|
-
> npm install inversify reflect-metadata --save
|
|
65
|
-
> yarn add inversify reflect-metadata
|
|
66
|
-
> pnpm add inversify reflect-metadata
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
`reflect-metadata` will be automatically imported by inversify.
|
|
70
|
-
|
|
71
|
-
The InversifyJS type definitions are included in the inversify npm package.
|
|
72
|
-
|
|
73
|
-
> :warning: **Important!** InversifyJS requires TypeScript >= 4.4 and the `experimentalDecorators`, `emitDecoratorMetadata`, compilation options in your `tsconfig.json` file.
|
|
74
|
-
|
|
75
|
-
```json
|
|
76
|
-
{
|
|
77
|
-
"compilerOptions": {
|
|
78
|
-
"experimentalDecorators": true,
|
|
79
|
-
"emitDecoratorMetadata": true
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
InversifyJS requires a modern JavaScript engine with support for:
|
|
85
|
-
|
|
86
|
-
- [Reflect metadata](https://rbuckton.github.io/reflect-metadata/)
|
|
87
|
-
- [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
|
|
88
|
-
- [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) (Only required if using [provider injection](https://github.com/inversify/InversifyJS/blob/master/wiki/provider_injection.md))
|
|
89
|
-
- [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) (Only required if using [activation handlers](https://github.com/inversify/InversifyJS/blob/master/wiki/activation_handler.md))
|
|
90
|
-
|
|
91
|
-
If your environment doesn't support one of these you will need to import a shim or polyfill.
|
|
92
|
-
|
|
93
|
-
Check out the [Environment support and polyfills](https://github.com/inversify/InversifyJS/blob/master/wiki/environment.md)
|
|
94
|
-
page in the wiki and the [Basic example](https://github.com/inversify/inversify-basic-example) to learn more.
|
|
95
|
-
|
|
96
|
-
## The Basics
|
|
97
|
-
Letβs take a look at the basic usage and APIs of InversifyJS with TypeScript:
|
|
98
|
-
|
|
99
|
-
### Step 1: Declare your interfaces and types
|
|
100
|
-
|
|
101
|
-
Our goal is to write code that adheres to the [dependency inversion principle](https://en.wikipedia.org/wiki/Dependency_inversion_principle).
|
|
102
|
-
This means that we should "depend upon Abstractions and do not depend upon concretions".
|
|
103
|
-
Let's start by declaring some interfaces (abstractions).
|
|
104
|
-
|
|
105
|
-
```ts
|
|
106
|
-
// file interfaces.ts
|
|
107
|
-
|
|
108
|
-
export interface Warrior {
|
|
109
|
-
fight(): string;
|
|
110
|
-
sneak(): string;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export interface Weapon {
|
|
114
|
-
hit(): string;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export interface ThrowableWeapon {
|
|
118
|
-
throw(): string;
|
|
119
|
-
}
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
InversifyJS needs to use the type as identifiers at runtime. We use symbols as identifiers but you can also use classes and or string literals.
|
|
123
|
-
|
|
124
|
-
PLEASE MAKE SURE TO PLACE THIS TYPES DECLARATION IN A SEPARATE FILE. (see bug #1455)
|
|
125
|
-
|
|
126
|
-
```ts
|
|
127
|
-
// file types.ts
|
|
128
|
-
|
|
129
|
-
const TYPES = {
|
|
130
|
-
Warrior: Symbol.for("Warrior"),
|
|
131
|
-
Weapon: Symbol.for("Weapon"),
|
|
132
|
-
ThrowableWeapon: Symbol.for("ThrowableWeapon")
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
export { TYPES };
|
|
136
|
-
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
> **Note**: It is recommended to use Symbols but InversifyJS also support the usage of Classes and string literals (please refer to the features section to learn more).
|
|
140
|
-
|
|
141
|
-
### Step 2: Declare dependencies using the `@injectable` & `@inject` decorators
|
|
142
|
-
Let's continue by declaring some classes (concretions). The classes are implementations of the interfaces that we just declared. We will annotate them with the `@injectable` decorator.
|
|
143
|
-
|
|
144
|
-
When a class has a dependency on an interface we also need to use the `@inject` decorator to define an identifier for the interface that will be available at runtime. In this case we will use the Symbols `Symbol.for("Weapon")` and `Symbol.for("ThrowableWeapon")` as runtime identifiers.
|
|
145
|
-
|
|
146
|
-
```ts
|
|
147
|
-
// file entities.ts
|
|
148
|
-
|
|
149
|
-
import { injectable, inject } from "inversify";
|
|
150
|
-
import { Weapon, ThrowableWeapon, Warrior } from "./interfaces";
|
|
151
|
-
import { TYPES } from "./types";
|
|
152
|
-
|
|
153
|
-
@injectable()
|
|
154
|
-
class Katana implements Weapon {
|
|
155
|
-
public hit() {
|
|
156
|
-
return "cut!";
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
@injectable()
|
|
161
|
-
class Shuriken implements ThrowableWeapon {
|
|
162
|
-
public throw() {
|
|
163
|
-
return "hit!";
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
@injectable()
|
|
168
|
-
class Ninja implements Warrior {
|
|
169
|
-
|
|
170
|
-
private _katana: Weapon;
|
|
171
|
-
private _shuriken: ThrowableWeapon;
|
|
172
|
-
|
|
173
|
-
constructor(
|
|
174
|
-
@inject(TYPES.Weapon) katana: Weapon,
|
|
175
|
-
@inject(TYPES.ThrowableWeapon) shuriken: ThrowableWeapon
|
|
176
|
-
) {
|
|
177
|
-
this._katana = katana;
|
|
178
|
-
this._shuriken = shuriken;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
public fight() { return this._katana.hit(); }
|
|
182
|
-
public sneak() { return this._shuriken.throw(); }
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export { Ninja, Katana, Shuriken };
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
If you prefer it you can use property injection instead of constructor injection so you don't have to declare the class constructor:
|
|
190
|
-
|
|
191
|
-
```ts
|
|
192
|
-
@injectable()
|
|
193
|
-
class Ninja implements Warrior {
|
|
194
|
-
@inject(TYPES.Weapon) private _katana: Weapon;
|
|
195
|
-
@inject(TYPES.ThrowableWeapon) private _shuriken: ThrowableWeapon;
|
|
196
|
-
public fight() { return this._katana.hit(); }
|
|
197
|
-
public sneak() { return this._shuriken.throw(); }
|
|
198
|
-
}
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
### Step 3: Create and configure a Container
|
|
202
|
-
We recommend to do this in a file named `inversify.config.ts`. This is the only place in which there is some coupling.
|
|
203
|
-
In the rest of your application your classes should be free of references to other classes.
|
|
204
|
-
```ts
|
|
205
|
-
// file inversify.config.ts
|
|
206
|
-
|
|
207
|
-
import { Container } from "inversify";
|
|
208
|
-
import { TYPES } from "./types";
|
|
209
|
-
import { Warrior, Weapon, ThrowableWeapon } from "./interfaces";
|
|
210
|
-
import { Ninja, Katana, Shuriken } from "./entities";
|
|
211
|
-
|
|
212
|
-
const myContainer = new Container();
|
|
213
|
-
myContainer.bind<Warrior>(TYPES.Warrior).to(Ninja);
|
|
214
|
-
myContainer.bind<Weapon>(TYPES.Weapon).to(Katana);
|
|
215
|
-
myContainer.bind<ThrowableWeapon>(TYPES.ThrowableWeapon).to(Shuriken);
|
|
216
|
-
|
|
217
|
-
export { myContainer };
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
### Step 4: Resolve dependencies
|
|
221
|
-
You can use the method `get<T>` from the `Container` class to resolve a dependency.
|
|
222
|
-
Remember that you should do this only in your [composition root](http://blog.ploeh.dk/2011/07/28/CompositionRoot/)
|
|
223
|
-
to avoid the [service locator anti-pattern](http://blog.ploeh.dk/2010/02/03/ServiceLocatorisanAnti-Pattern/).
|
|
224
|
-
|
|
225
|
-
```ts
|
|
226
|
-
import { myContainer } from "./inversify.config";
|
|
227
|
-
import { TYPES } from "./types";
|
|
228
|
-
import { Warrior } from "./interfaces";
|
|
229
|
-
|
|
230
|
-
const ninja = myContainer.get<Warrior>(TYPES.Warrior);
|
|
231
|
-
|
|
232
|
-
expect(ninja.fight()).eql("cut!"); // true
|
|
233
|
-
expect(ninja.sneak()).eql("hit!"); // true
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
As we can see the `Katana` and `Shuriken` were successfully resolved and injected into `Ninja`.
|
|
237
|
-
|
|
238
|
-
InversifyJS supports ES5 and ES6 and can work without TypeScript.
|
|
239
|
-
Head to the [**JavaScript example**](https://github.com/inversify/InversifyJS/blob/master/wiki/basic_js_example.md) to learn more!
|
|
240
|
-
|
|
241
|
-
## π The InversifyJS Features and API
|
|
242
|
-
Let's take a look to the InversifyJS features!
|
|
243
|
-
|
|
244
|
-
- [Support for classes](https://github.com/inversify/InversifyJS/blob/master/wiki/classes_as_id.md)
|
|
245
|
-
- [Support for Symbols](https://github.com/inversify/InversifyJS/blob/master/wiki/symbols_as_id.md)
|
|
246
|
-
- [Container API](https://github.com/inversify/InversifyJS/blob/master/wiki/container_api.md)
|
|
247
|
-
- [Declaring container modules](https://github.com/inversify/InversifyJS/blob/master/wiki/container_modules.md)
|
|
248
|
-
- [Container snapshots](https://github.com/inversify/InversifyJS/blob/master/wiki/container_snapshots.md)
|
|
249
|
-
- [Controlling the scope of the dependencies](https://github.com/inversify/InversifyJS/blob/master/wiki/scope.md)
|
|
250
|
-
- [Declaring optional dependencies](https://github.com/inversify/InversifyJS/blob/master/wiki/optional_dependencies.md)
|
|
251
|
-
- [Injecting a constant or dynamic value](https://github.com/inversify/InversifyJS/blob/master/wiki/value_injection.md)
|
|
252
|
-
- [Injecting a class constructor](https://github.com/inversify/InversifyJS/blob/master/wiki/constructor_injection.md)
|
|
253
|
-
- [Injecting a Factory](https://github.com/inversify/InversifyJS/blob/master/wiki/factory_injection.md)
|
|
254
|
-
- [Auto factory](https://github.com/inversify/InversifyJS/blob/master/wiki/auto_factory.md)
|
|
255
|
-
- [Auto named factory](https://github.com/inversify/InversifyJS/blob/master/wiki/auto_named_factory.md)
|
|
256
|
-
- [Injecting a Provider (asynchronous Factory)](https://github.com/inversify/InversifyJS/blob/master/wiki/provider_injection.md)
|
|
257
|
-
- [Activation handler](https://github.com/inversify/InversifyJS/blob/master/wiki/activation_handler.md)
|
|
258
|
-
- [Deactivation handler](https://github.com/inversify/InversifyJS/blob/master/wiki/deactivation_handler.md)
|
|
259
|
-
- [Post Construct decorator](https://github.com/inversify/InversifyJS/blob/master/wiki/post_construct.md)
|
|
260
|
-
- [Middleware](https://github.com/inversify/InversifyJS/blob/master/wiki/middleware.md)
|
|
261
|
-
- [Multi-injection](https://github.com/inversify/InversifyJS/blob/master/wiki/multi_injection.md)
|
|
262
|
-
- [Tagged bindings](https://github.com/inversify/InversifyJS/blob/master/wiki/tagged_bindings.md)
|
|
263
|
-
- [Create your own tag decorators](https://github.com/inversify/InversifyJS/blob/master/wiki/custom_tag_decorators.md)
|
|
264
|
-
- [Named bindings](https://github.com/inversify/InversifyJS/blob/master/wiki/named_bindings.md)
|
|
265
|
-
- [Default target](https://github.com/inversify/InversifyJS/blob/master/wiki/default_targets.md)
|
|
266
|
-
- [Support for hierarchical DI systems](https://github.com/inversify/InversifyJS/blob/master/wiki/hierarchical_di.md)
|
|
267
|
-
- [Contextual bindings & @targetName](https://github.com/inversify/InversifyJS/blob/master/wiki/contextual_bindings.md)
|
|
268
|
-
- [Property injection](https://github.com/inversify/InversifyJS/blob/master/wiki/property_injection.md)
|
|
269
|
-
- [Circular dependencies](https://github.com/inversify/InversifyJS/blob/master/wiki/circular_dependencies.md)
|
|
270
|
-
- [Inheritance](https://github.com/inversify/InversifyJS/blob/master/wiki/inheritance.md)
|
|
271
|
-
|
|
272
|
-
Please refer to the [wiki](https://github.com/inversify/InversifyJS/blob/master/wiki/readme.md) for additional details.
|
|
273
|
-
|
|
274
|
-
## π§© Ecosystem
|
|
275
|
-
In order to provide a state of the art development experience we are also working on:
|
|
276
|
-
|
|
277
|
-
- [Middleware extensions](https://github.com/inversify/InversifyJS/blob/master/wiki/ecosystem.md#extensions).
|
|
278
|
-
- [Development tools](https://github.com/inversify/InversifyJS/blob/master/wiki/ecosystem.md#development-tools).
|
|
279
|
-
- [Examples](https://github.com/inversify/InversifyJS/blob/master/wiki/ecosystem.md#examples).
|
|
280
|
-
|
|
281
|
-
Please refer to the [ecosystem wiki page](https://github.com/inversify/InversifyJS/blob/master/wiki/ecosystem.md) to learn more.
|
|
282
|
-
|
|
283
|
-
## Support
|
|
284
|
-
If you are experience any kind of issues we will be happy to help. You can report an issue using the [issues page](https://github.com/inversify/InversifyJS/issues) or the [chat](https://gitter.im/inversify/InversifyJS). You can also ask questions at [Stack overflow](http://stackoverflow.com/tags/inversifyjs) using the `inversifyjs` tag.
|
|
285
|
-
|
|
286
|
-
If you want to share your thoughts with the development team or join us you will be able to do so using the [official the mailing list](https://groups.google.com/forum/#!forum/inversifyjs). You can check out the
|
|
287
|
-
[wiki](https://github.com/inversify/InversifyJS/blob/master/wiki/readme.md) to learn more about InversifyJS internals.
|
|
59
|
+
## π Documentation
|
|
60
|
+
Documentation is available at https://inversify.io
|
|
288
61
|
|
|
289
62
|
## Acknowledgements
|
|
290
63
|
|
package/package.json
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
"description": "A powerful and lightweight inversion of control container for JavaScript and Node.js apps powered by TypeScript.",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@inversifyjs/common": "1.5.0",
|
|
9
|
-
"@inversifyjs/container": "1.
|
|
10
|
-
"@inversifyjs/core": "3.
|
|
9
|
+
"@inversifyjs/container": "1.5.0",
|
|
10
|
+
"@inversifyjs/core": "3.5.0"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"@eslint/js": "9.19.0",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"@types/chai": "4.3.20",
|
|
17
17
|
"@types/mocha": "10.0.10",
|
|
18
18
|
"@types/sinon": "17.0.3",
|
|
19
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
20
|
-
"@typescript-eslint/parser": "8.
|
|
19
|
+
"@typescript-eslint/eslint-plugin": "8.22.0",
|
|
20
|
+
"@typescript-eslint/parser": "8.22.0",
|
|
21
21
|
"chai": "4.5.0",
|
|
22
22
|
"eslint": "9.19.0",
|
|
23
23
|
"eslint-config-prettier": "10.0.1",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"ts-loader": "9.5.2",
|
|
33
33
|
"ts-node": "10.9.2",
|
|
34
34
|
"typescript": "5.7.3",
|
|
35
|
-
"typescript-eslint": "8.
|
|
35
|
+
"typescript-eslint": "8.22.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"reflect-metadata": "~0.2.2"
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"test:cjs": "nyc --reporter=lcov mocha lib/cjs/test/*.test.js lib/cjs/test/**/*.test.js --reporter spec"
|
|
78
78
|
},
|
|
79
79
|
"sideEffects": false,
|
|
80
|
-
"version": "7.0.0-alpha.
|
|
80
|
+
"version": "7.0.0-alpha.3"
|
|
81
81
|
}
|