@fastrack/di 0.1.0
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/LICENSE +21 -0
- package/README.md +31 -0
- package/dist/container.d.ts +14 -0
- package/dist/container.d.ts.map +1 -0
- package/dist/container.js +16 -0
- package/dist/container.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/package.json +34 -0
- package/src/container.ts +17 -0
- package/src/index.ts +9 -0
- package/tsconfig.json +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Fastrack
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @fastrack/di
|
|
2
|
+
|
|
3
|
+
Inversify-style dependency injection for Fastrack: constructor injection only, singleton scope by default, explicit bindings via `ContainerModule`. DI never auto-registers routes; Fastify plugins stay responsible for HTTP boundaries.
|
|
4
|
+
|
|
5
|
+
See [docs/architecture.md](../../docs/architecture.md).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @fastrack/di
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { createContainer, bind } from "@fastrack/di";
|
|
17
|
+
import { MyService } from "./my-service.js";
|
|
18
|
+
|
|
19
|
+
const container = createContainer();
|
|
20
|
+
container.load(
|
|
21
|
+
bind(MyService).toSelf().inSingletonScope()
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const service = container.get(MyService);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Rules
|
|
28
|
+
|
|
29
|
+
- Constructor injection only.
|
|
30
|
+
- Singleton scope default.
|
|
31
|
+
- Explicit bindings via ContainerModule; no auto-registration of routes.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { Container, type interfaces } from "inversify";
|
|
3
|
+
/**
|
|
4
|
+
* Create a new DI container. Inversify-style: constructor injection only, singleton default.
|
|
5
|
+
* DI never auto-registers routes; Fastify plugins own HTTP boundaries.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* const container = createContainer();
|
|
9
|
+
* container.bind(MyService).toSelf().inSingletonScope();
|
|
10
|
+
* const service = container.get(MyService);
|
|
11
|
+
*/
|
|
12
|
+
export declare function createContainer(): Container;
|
|
13
|
+
export { Container, type interfaces };
|
|
14
|
+
//# sourceMappingURL=container.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../src/container.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,IAAI,SAAS,CAE3C;AAED,OAAO,EAAE,SAAS,EAAE,KAAK,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { Container } from "inversify";
|
|
3
|
+
/**
|
|
4
|
+
* Create a new DI container. Inversify-style: constructor injection only, singleton default.
|
|
5
|
+
* DI never auto-registers routes; Fastify plugins own HTTP boundaries.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* const container = createContainer();
|
|
9
|
+
* container.bind(MyService).toSelf().inSingletonScope();
|
|
10
|
+
* const service = container.get(MyService);
|
|
11
|
+
*/
|
|
12
|
+
export function createContainer() {
|
|
13
|
+
return new Container({ defaultScope: "Singleton" });
|
|
14
|
+
}
|
|
15
|
+
export { Container };
|
|
16
|
+
//# sourceMappingURL=container.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container.js","sourceRoot":"","sources":["../src/container.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAmB,MAAM,WAAW,CAAC;AAEvD;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,IAAI,SAAS,CAAC,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC,CAAC;AACtD,CAAC;AAED,OAAO,EAAE,SAAS,EAAmB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
/**
|
|
3
|
+
* @fastrack/di — Inversify-style DI: constructor injection, singleton default, explicit bindings.
|
|
4
|
+
* DI never auto-registers routes; Fastify plugins own HTTP boundaries.
|
|
5
|
+
* @see https://github.com/fastrack-platform-js/fastrack
|
|
6
|
+
*/
|
|
7
|
+
export { createContainer, Container, type interfaces } from "./container.js";
|
|
8
|
+
export { injectable, inject } from "inversify";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B;;;;GAIG;AACH,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
/**
|
|
3
|
+
* @fastrack/di — Inversify-style DI: constructor injection, singleton default, explicit bindings.
|
|
4
|
+
* DI never auto-registers routes; Fastify plugins own HTTP boundaries.
|
|
5
|
+
* @see https://github.com/fastrack-platform-js/fastrack
|
|
6
|
+
*/
|
|
7
|
+
export { createContainer, Container } from "./container.js";
|
|
8
|
+
export { injectable, inject } from "inversify";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B;;;;GAIG;AACH,OAAO,EAAE,eAAe,EAAE,SAAS,EAAmB,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fastrack/di",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"inversify": "^6.0.2",
|
|
16
|
+
"reflect-metadata": "^0.2.2"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"typescript": "^5.6.3"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public",
|
|
23
|
+
"registry": "https://registry.npmjs.org/"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc -p tsconfig.json",
|
|
30
|
+
"clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
31
|
+
"lint": "echo ok",
|
|
32
|
+
"test": "echo ok"
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/container.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { Container, type interfaces } from "inversify";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Create a new DI container. Inversify-style: constructor injection only, singleton default.
|
|
6
|
+
* DI never auto-registers routes; Fastify plugins own HTTP boundaries.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* const container = createContainer();
|
|
10
|
+
* container.bind(MyService).toSelf().inSingletonScope();
|
|
11
|
+
* const service = container.get(MyService);
|
|
12
|
+
*/
|
|
13
|
+
export function createContainer(): Container {
|
|
14
|
+
return new Container({ defaultScope: "Singleton" });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { Container, type interfaces };
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @fastrack/di — Inversify-style DI: constructor injection, singleton default, explicit bindings.
|
|
5
|
+
* DI never auto-registers routes; Fastify plugins own HTTP boundaries.
|
|
6
|
+
* @see https://github.com/fastrack-platform-js/fastrack
|
|
7
|
+
*/
|
|
8
|
+
export { createContainer, Container, type interfaces } from "./container.js";
|
|
9
|
+
export { injectable, inject } from "inversify";
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "dist",
|
|
5
|
+
"rootDir": "src",
|
|
6
|
+
"experimentalDecorators": true,
|
|
7
|
+
"emitDecoratorMetadata": true
|
|
8
|
+
},
|
|
9
|
+
"include": ["src/**/*"],
|
|
10
|
+
"exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.spec.ts"]
|
|
11
|
+
}
|