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: docs/documentation/get_it/async_objects.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,11 +16,11 @@ GetIt provides comprehensive support for asynchronous object creation and initia
16
16
17
17
<strong>Key capabilities:</strong>
18
18
<ulstyle="list-style: none; padding-left: 0;">
19
-
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅️ <strong><ahref="#async-factories">Async Factories</a></strong> - Create new instances asynchronously on each access</li>
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅️ <strong><ahref="#manual-ready-signaling">Manual Signaling</a></strong> - Fine-grained control over ready state</li>
19
+
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ <strong><ahref="#async-factories">Async Factories</a></strong> - Create new instances asynchronously on each access</li>
@@ -199,9 +199,9 @@ Circular dependencies often mean:
199
199
- Logic should be in a third service that coordinates both
200
200
201
201
<strong>What NOT to do:</strong>
202
-
❌️ Using `late` without proper initialization
203
-
❌️ Using global variables to break the cycle
204
-
❌️ Passing getIt instance around
202
+
❌ Using `late` without proper initialization
203
+
❌ Using global variables to break the cycle
204
+
❌ Passing getIt instance around
205
205
:::
206
206
207
207
## Why do I get "This instance is not available in GetIt" when calling signalReady?
@@ -271,17 +271,17 @@ Split registrations into separate functions that encapsulate scope management:
271
271
272
272
<strong>Why functions matter:</strong>
273
273
<ulstyle="list-style: none; padding-left: 0;">
274
-
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅️ <strong>Reusable</strong> - Call the same function when pushing scopes to reinitialize features</li>
275
-
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅️ <strong>Testable</strong> - Call specific registration functions in test setup</li>
276
-
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅️ <strong>Organized</strong> - Clear separation of concerns by feature/layer</li>
277
-
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅️ <strong>Centralized</strong> - All registration logic in one place, not scattered</li>
274
+
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ <strong>Reusable</strong> - Call the same function when pushing scopes to reinitialize features</li>
275
+
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ <strong>Testable</strong> - Call specific registration functions in test setup</li>
276
+
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ <strong>Organized</strong> - Clear separation of concerns by feature/layer</li>
277
+
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ <strong>Centralized</strong> - All registration logic in one place, not scattered</li>
278
278
</ul>
279
279
280
280
<strong>Don't:</strong>
281
-
❌️ Scatter registration calls throughout your app
282
-
❌️ Call registration methods from widget code
283
-
❌️ Mix registration with business logic
284
-
❌️ Duplicate registration code for different scopes
281
+
❌ Scatter registration calls throughout your app
282
+
❌ Call registration methods from widget code
283
+
❌ Mix registration with business logic
284
+
❌ Duplicate registration code for different scopes
285
285
286
286
See [Scopes documentation](/documentation/get_it/scopes) for more on scope-based architecture.
287
287
:::
@@ -292,21 +292,21 @@ See [Scopes documentation](/documentation/get_it/scopes) for more on scope-based
292
292
293
293
Use <strong>scopes</strong> - they're designed for this exact use case:
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅️ Automatic cleanup and restoration</li>
306
-
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅️ Can't forget to re-register original services</li>
307
-
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅️ Dispose functions called automatically</li>
308
-
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅️ Cleaner, less error-prone code</li>
309
-
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅️ Can push multiple nested scopes</li>
305
+
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ Automatic cleanup and restoration</li>
306
+
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ Can't forget to re-register original services</li>
307
+
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ Dispose functions called automatically</li>
308
+
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ Cleaner, less error-prone code</li>
309
+
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ Can push multiple nested scopes</li>
310
310
</ul>
311
311
312
312
<strong>Use unregister when:</strong>
@@ -332,16 +332,16 @@ See [Scopes documentation](/documentation/get_it/scopes) for more patterns.
332
332
333
333
<strong>When to use injectable:</strong>
334
334
<ulstyle="list-style: none; padding-left: 0;">
335
-
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅️ Large apps with many services (50+)</li>
336
-
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅️ You prefer declarative over imperative code</li>
337
-
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅️ You want dependency injection to be more automatic</li>
335
+
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ Large apps with many services (50+)</li>
336
+
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ You prefer declarative over imperative code</li>
337
+
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ You want dependency injection to be more automatic</li>
338
338
</ul>
339
339
340
340
<strong>When manual registration is fine:</strong>
341
341
<ulstyle="list-style: none; padding-left: 0;">
342
-
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅️ Small to medium apps (< 50 services)</li>
343
-
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅️ You prefer explicit, straightforward code</li>
344
-
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅️ You want to avoid code generation build step</li>
342
+
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ Small to medium apps (< 50 services)</li>
343
+
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ You prefer explicit, straightforward code</li>
344
+
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ You want to avoid code generation build step</li>
345
345
</ul>
346
346
347
347
<strong>Important:</strong> injectable is <strong>optional</strong>. get_it works great without it! The documentation here focuses on manual registration, which is simpler to learn and works for most apps.
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅️ <strong>Easy to test</strong> - Switch implementations for mocks in tests</li>
22
-
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅️ <strong>No BuildContext needed</strong> - Access from anywhere in your app (UI, business logic, anywhere)</li>
23
-
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅️ <strong>Type safe</strong> - Compile-time type checking</li>
24
-
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅️ <strong>No code generation</strong> - Works without build_runner</li>
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ <strong>Easy to test</strong> - Switch implementations for mocks in tests</li>
22
+
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ <strong>No BuildContext needed</strong> - Access from anywhere in your app (UI, business logic, anywhere)</li>
23
+
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ <strong>Type safe</strong> - Compile-time type checking</li>
24
+
<listyle="padding-left: 1.5em; text-indent: -1.5em;">✅ <strong>No code generation</strong> - Works without build_runner</li>
25
25
</ul>
26
26
27
27
<strong>Common use cases:</strong>
@@ -106,11 +106,11 @@ This is simpler and makes IDE navigation to implementation easier.
106
106
107
107
<strong>When to use interfaces:</strong>
108
108
<ul style="list-style: none; padding-left: 0;">
109
-
<li style="padding-left: 1.5em; text-indent: -1.5em;">✅️ Multiple implementations (production vs test, different providers)</li>
110
-
<li style="padding-left: 1.5em; text-indent: -1.5em;">✅️ Platform-specific implementations (mobile vs web)</li>
111
-
<li style="padding-left: 1.5em; text-indent: -1.5em;">✅️ Feature flags to switch implementations</li>
109
+
<li style="padding-left: 1.5em; text-indent: -1.5em;">✅ Multiple implementations (production vs test, different providers)</li>
110
+
<li style="padding-left: 1.5em; text-indent: -1.5em;">✅ Platform-specific implementations (mobile vs web)</li>
111
+
<li style="padding-left: 1.5em; text-indent: -1.5em;">✅ Feature flags to switch implementations</li>
112
112
</ul>
113
-
- ❌️ Don't use "just because" - creates navigation friction in your IDE
113
+
- ❌ Don't use "just because" - creates navigation friction in your IDE
114
114
115
115
---
116
116
@@ -168,28 +168,28 @@ As your app grows, you need to separate business logic from UI code. This makes
168
168
<strong>Traditional approaches and their limitations:</strong>
169
169
170
170
<strong>InheritedWidget / Provider:</strong>
171
-
- ❌️ Requires `BuildContext` (not available in business layer)
172
-
- ❌️ Adds complexity to widget tree
173
-
- ❌️ Hard to access from background tasks, isolates
171
+
- ❌ Requires `BuildContext` (not available in business layer)
172
+
- ❌ Adds complexity to widget tree
173
+
- ❌ Hard to access from background tasks, isolates
174
174
175
175
<strong>Plain Singletons:</strong>
176
-
- ❌️ Can't swap implementation for tests
177
-
- ❌️ Tight coupling to concrete classes
178
-
- ❌️ No lifecycle management
176
+
- ❌ Can't swap implementation for tests
177
+
- ❌ Tight coupling to concrete classes
178
+
- ❌ No lifecycle management
179
179
180
180
<strong>IoC/DI Containers:</strong>
181
-
- ❌️ Slow startup (reflection-based)
182
-
- ❌️ "Magic" - hard to understand where objects come from
183
-
- ❌️ Most don't work with Flutter (no reflection)
181
+
- ❌ Slow startup (reflection-based)
182
+
- ❌ "Magic" - hard to understand where objects come from
183
+
- ❌ Most don't work with Flutter (no reflection)
184
184
185
185
<strong>get_it solves these problems:</strong>
186
186
<ul style="list-style: none; padding-left: 0;">
187
-
<li style="padding-left: 1.5em; text-indent: -1.5em;">✅️ Access from anywhere without BuildContext</li>
188
-
<li style="padding-left: 1.5em; text-indent: -1.5em;">✅️ Easy to mock for tests (register interface, swap implementation)</li>
189
-
<li style="padding-left: 1.5em; text-indent: -1.5em;">✅️ Extremely fast (no reflection, just Map lookup)</li>
190
-
<li style="padding-left: 1.5em; text-indent: -1.5em;">✅️ Clear and explicit (you see exactly what's registered)</li>
0 commit comments