getbox 1.3.0 → 1.3.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.
Files changed (2) hide show
  1. package/README.md +10 -12
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -6,8 +6,6 @@
6
6
 
7
7
  Callers know the type of the value they need, but not how it will be derived. The box resolves constructors lazily and caches instances automatically.
8
8
 
9
- For an alternative pattern using AsyncLocalStorage where classes can resolve dependencies directly in their constructors, see [getbox/context](./CONTEXT.md).
10
-
11
9
  ## Installation
12
10
 
13
11
  ```sh
@@ -16,7 +14,9 @@ npm install getbox
16
14
 
17
15
  ## Usage
18
16
 
19
- `getbox` has a very small API surface. You typically only need to use the `Box.get()` and optionally static init methods or the `factory` helper.
17
+ `getbox` has a very small API surface. You typically only need `box.get()` and optionally `static init` or the `factory` helper.
18
+
19
+ For an alternative pattern using AsyncLocalStorage where classes can resolve dependencies directly in their constructors, see [getbox/context](./CONTEXT.md).
20
20
 
21
21
  ### Create a class
22
22
 
@@ -33,11 +33,11 @@ export class Printer {
33
33
 
34
34
  ### Use in another class
35
35
 
36
- Retrieve instances by calling `box.get(Constructor)` within your class constructor or factory function.
36
+ The `static init` property tells the box what dependencies to pass when instantiating the class.
37
37
 
38
38
  ```ts
39
39
  // office.ts
40
- import { Box, factory } from "getbox";
40
+ import { Box } from "getbox";
41
41
  import { Printer } from "./printer";
42
42
 
43
43
  export class Office {
@@ -103,14 +103,12 @@ export interface Logger {
103
103
  log(message: string): void;
104
104
  }
105
105
 
106
- export class ConsoleLogger implements Logger {
107
- log(message: string): void {
108
- console.log(`[LOG] ${message}`);
109
- }
110
- }
111
-
112
106
  const LoggerFactory = factory((box: Box): Logger => {
113
- return new ConsoleLogger();
107
+ return {
108
+ log(message: string): void {
109
+ console.log(`[LOG] ${message}`);
110
+ },
111
+ };
114
112
  });
115
113
  ```
116
114
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "getbox",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Lightweight dependency injection for TypeScript",
5
5
  "private": false,
6
6
  "main": "./dist/index.cjs",