You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+12-10Lines changed: 12 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,18 +8,20 @@ A dead-simple, modern, and lightweight (~4kb) Dependency Injection library for T
8
8
9
9
### **Why another DI framework?**
10
10
11
-
Many existing DI libraries for TypeScript rely on the older "experimental" decorators and reflection libraries like reflect-metadata. This approach forces you to enable emitDecoratorMetadata in your tsconfig.json, which depends on TypeScript's type-information—information that is erased at compile time.
11
+
Stimshot was inspired from InversifyJS, Tsyringe, InjectionJS (outsize the context of Angular). These libraries have some fundamental issues when used with modern TypeScript.
12
12
13
-
This can lead to a fragile, guess-work setup.
13
+
Many existing DI libraries for TypeScript rely on the older experimental decorators and reflection libraries like `reflect-metadata`. This approach forces you to enable `emitDecoratorMetadata` in your `tsconfig.json`, which depends on TypeScript's type-information—information that is erased at compile time.
14
14
15
-
stimshot was built with a different philosophy:
15
+
Often this leads to runtime errors, especially when using the new [`import type` syntax](https://www.google.com/search?q=typescript+import+type+syntax). Most DI libraries were not designed with this in mind, and as a result, they fail to resolve dependencies correctly and lead to runtime issues.
16
16
17
-
***Explicit & Guess-less:** No magic strings, no fragile type-reflection. You explicitly ask for what you need.
17
+
Stimshot was built with a different philosophy:
18
+
19
+
***Explicit & Guess-less:** No magic strings, no fragile type-reflection. You explicitly ask for what you need. What you see is what you get.
18
20
***Weightless:** The entire library is one small file with no dependencies.
19
21
***Modern:** Built for modern TypeScript (5.0+) using standard Stage 3 Decorators.
20
22
***Simple APIs:** The API surface is tiny, intuitive, and easy to understand.
21
23
22
-
This library **does not** use or require reflect-metadata or experimentalDecorators like other DI libraries.
24
+
This library **does not** use or require `reflect-metadata` or `experimentalDecorators` or `emitDecoratorMetadata` like other DI libraries.
23
25
24
26
### **Why Use Dependency Injection?**
25
27
@@ -124,17 +126,17 @@ You can also replace with a simple object (`useValue`) or a function (`useFactor
124
126
125
127
#### **Decorators**
126
128
127
-
***@shared()**: Class decorator. Registers the class as a "singleton." A single instance will be created on the first resolve and shared for all subsequent calls.
128
-
***@fresh()**: Class decorator. Registers the class as a "prototype." A new instance will be created *every time* it is resolved.
129
+
***`@shared()`**: Class decorator. Registers the class as a "singleton." A single instance will be created on the first resolve and shared for all subsequent calls (This is what you usually want).
130
+
***`@fresh()`**: Class decorator. Registers the class as a "prototype." A new instance will be created *every time* it is resolved.
129
131
130
132
#### **Functions**
131
133
132
-
***resolve(Token)**: Resolves a dependency from the container. Token is the class constructor (e.g., resolve(Database)).
133
-
***replace(Token, options)**: Used for testing. Replaces the registered Token with a mock implementation.
134
+
***`resolve(Token)`**: Resolves a dependency from the container. Token is the class constructor (e.g., resolve(Database)).
135
+
***`replace(Token, options)`**: Used for testing. Replaces the registered Token with a mock implementation.
134
136
* options.useClass: Replaces with another registered class.
135
137
* options.useValue: Replaces with a specific value (e.g., a mock object).
136
138
* options.useFactory: Replaces with a function that returns the instance.
137
-
***reset()**: Used for testing. Resets the entire container, clearing all shared instances and removing all replacements, restoring the original configuration.
139
+
***`reset()`**: Used for testing. Resets the entire container, clearing all shared instances and removing all replacements, restoring the original configuration.
0 commit comments