@goodie-ts/core 0.1.0 → 0.1.1
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/README.md +45 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# @goodie-ts/core
|
|
2
|
+
|
|
3
|
+
Runtime dependency injection container for [goodie-ts](https://github.com/GOOD-Code-ApS/goodie).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @goodie-ts/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
This package provides the runtime container that resolves pre-built `BeanDefinition[]` arrays generated by [`@goodie-ts/transformer`](https://www.npmjs.com/package/@goodie-ts/transformer). No reflection, no scanning — just a fast topological sort and lazy instantiation.
|
|
14
|
+
|
|
15
|
+
## Key Exports
|
|
16
|
+
|
|
17
|
+
- **`ApplicationContext`** — DI container with `create()`, `get()`, `getAsync()`, `getAll()`, `close()`
|
|
18
|
+
- **`Goodie` / `GoodieBuilder`** — Bootstrap builder: `Goodie.build(definitions).start()`
|
|
19
|
+
- **`InjectionToken<T>`** — Typed token for interfaces, primitives, and generics
|
|
20
|
+
- **`BeanDefinition<T>`** — Bean descriptor with token, scope, factory, dependencies, and metadata
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { Goodie } from '@goodie-ts/core';
|
|
26
|
+
import { definitions } from './AppContext.generated.js';
|
|
27
|
+
|
|
28
|
+
const app = await Goodie.build(definitions).start();
|
|
29
|
+
const userService = app.context.get(UserService);
|
|
30
|
+
|
|
31
|
+
// When done:
|
|
32
|
+
await app.context.close();
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## API
|
|
36
|
+
|
|
37
|
+
- `ApplicationContext.create(defs)` — async factory, topo-sorts and validates the dependency graph
|
|
38
|
+
- `ctx.get(token)` — synchronous lookup (throws for unresolved async beans)
|
|
39
|
+
- `ctx.getAsync(token)` — always safe for async factories
|
|
40
|
+
- `ctx.getAll(token)` — returns all beans registered under a token
|
|
41
|
+
- `ctx.close()` — tears down the context
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
[MIT](https://github.com/GOOD-Code-ApS/goodie/blob/main/LICENSE)
|