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
+9-9Lines changed: 9 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ Please see [Synchronizing asynchronous initializations of Singletons](#synchroni
14
14
15
15
## Why GetIt
16
16
17
-
As your App grows, at some point you you will need to put your app's logic in classes that are separated from your Widgets. Keeping your widgets from having direct dependencies makes your code better organized and easier to test and maintain.
17
+
As your App grows, at some point you will need to put your app's logic in classes that are separated from your Widgets. Keeping your widgets from having direct dependencies makes your code better organized and easier to test and maintain.
18
18
But now you need a way to access these objects from your UI code. When I came to Flutter from the .Net world, the only way to do this was the use of InheritedWidgets. I found the way to use them by wrapping them in a StatefulWidget; quite cumbersome and has problems working consistently. Also:
19
19
20
20
* I missed the ability to easily switch the implementation for a mocked version without changing the UI.
@@ -28,8 +28,8 @@ Accessing an object from anywhere in an App can be done by other ways, but:
28
28
29
29
As I was used to use the Service Locator _Splat_ from .Net, I decided to port it to Dart. Since then, more features have been added.
30
30
31
-
>If you are not familiar with the concept of Service Locators, its a way to decouple the interface (abstract base class) from a concrete implementation, and at the same time allows to access the concrete implementation from everywhere in your App over the interface.
32
-
> I can only highly recommend to read this classic article by from Martin Fowler [Inversion of Control Containers and the Dependency Injection pattern](https://martinfowler.com/articles/injection.html)
31
+
>If you are not familiar with the concept of Service Locators, it's a way to decouple the interface (abstract base class) from a concrete implementation, and at the same time allows to access the concrete implementation from everywhere in your App over the interface.
32
+
> I can only highly recommend to read this classic article by from Martin Fowler [Inversion of Control Containers and the Dependency Injection pattern](https://martinfowler.com/articles/injection.html).
Additionally you can register asynchronous Singletons which means Singletons that have an initialisation that requires async function calls. To be able to control such asynchronous start-up behaviour GetIt supports mechanisms to ensure the correct initialization sequence.
225
+
Additionally you can register asynchronous Singletons which means Singletons that have an initialization that requires async function calls. To be able to control such asynchronous start-up behaviour GetIt supports mechanisms to ensure the correct initialization sequence.
226
226
227
227
228
228
You create an Singleton with an asynchronous creation function
@@ -421,8 +421,8 @@ These parameters are passed as `dynamics` (otherwise I would have had add more g
421
421
### Unit Tests
422
422
When you are writing unit tests with GetIt in your App you have two possibilities:
423
423
424
-
*register all the Objects you need inside your unit Tests so that GetIt can provide its objects to the objects tat you are testing
425
-
*pass your dependent objects into the constructor of you test objects like:
424
+
*Register all the Objects you need inside your unit Tests so that GetIt can provide its objects to the objects that you are testing.
425
+
*Pass your dependent objects into the constructor of your test objects like:
426
426
427
427
```Dart
428
428
GetIt getIt = GetIt.instance;
@@ -438,10 +438,10 @@ class UserManager {
438
438
}
439
439
```
440
440
441
-
This way you don't need to pass them in the `AppModel` and `dbService` inside your App but you can pass them(or a mocked version) in your Unit tests
441
+
This way you don't need to pass them in the `AppModel` and `dbService` inside your App but you can pass them(or a mocked version) in your Unit tests.
442
442
443
443
### Integration Tests
444
-
If you have a mocked version of a Service, you can easily switch between that and the real one based on a some flag:
444
+
If you have a mocked version of a Service, you can easily switch between that and the real one based on a flag:
445
445
446
446
```Dart
447
447
if (testing) {
@@ -455,7 +455,7 @@ If you have a mocked version of a Service, you can easily switch between that an
455
455
456
456
### Named registration
457
457
458
-
**DON'T USE THIS IF UNLESS REALLY KNOW WHAT YOU ARE DOING!!!**
458
+
**DON'T USE THIS UNLESS YOU REALLY KNOW WHAT YOU ARE DOING!!!**
459
459
460
460
This should be your last resort as you can lose type safety.
0 commit comments