Skip to content

Commit 159dc0d

Browse files
committed
fix typo and remove unneeded whitespace chars in readme.md file
1 parent 2e59eda commit 159dc0d

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

README.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ Typical usage:
88
* Accessing service objects like REST API clients, databases so that they easily can be mocked.
99
* Accessing View/AppModels/Managers/BLoCs from Flutter Views
1010

11-
>**Breaking Change with V4.0.0**
11+
>**Breaking Change with V4.0.0**
1212
Principle on how to synchronize your registered instances creation has been rethought and improved :-)
1313
Please see [Synchronizing asynchronous initialisations of Singletons](#synchronizing-asynchronous-initialisations-of-singletons).
1414

1515
## Why GetIt
1616

17-
When your App grows at some point you you will start to put your app's logic in classes that are separated from your Widgets and have no dependency to Flutter which makes your code better organized and easier to test and maintain.
17+
When your App grows at some point you will start to put your app's logic in classes that are separated from your Widgets and have no dependency to Flutter which makes your code better organized and easier to test and maintain.
1818
But now you need a way how 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 had always problems getting it updating the widgets to work. Also:
1919

2020
* I was missing the ability to easily switch the implementation for a business object for a mocked one without changing the UI.
21-
* The fact that you need a `BuildContext` to access your objects made it unusable to use them from inside the Business layer.
21+
* The fact that you need a `BuildContext` to access your objects made it unusable to use them from inside the Business layer.
2222

2323
Accessing an object from anywhere in an App can be done by other ways too but:
2424

@@ -47,7 +47,7 @@ final getIt = GetIt.instance;
4747
void setup() {
4848
getIt.registerSingleton<AppModel>(AppModel());
4949
50-
// Alternatively you could write it if you don't like global variables
50+
// Alternatively you could write it if you don't like global variables
5151
GetIt.I.registerSingleton<AppModel>(AppModel());
5252
}
5353
```
@@ -85,7 +85,7 @@ Through this any call to `instance` in any package of a project will get the sam
8585
GetIt getIt = GetIt.instance;
8686
```
8787

88-
> You can use any name you want which makes Brian happy like (`sl, backend, services...`) ;-)
88+
> You can use any name you want which makes Brian happy like (`sl, backend, services...`) ;-)
8989
9090
Before you can access your objects you have to register them within `GetIt` typically direct in your start-up code.
9191

@@ -125,7 +125,7 @@ var myAppModel = GetIt.I<AppModel>();
125125

126126
#### Factory
127127

128-
```Dart
128+
```Dart
129129
void registerFactory<T>(FactoryFunc<T> func)
130130
```
131131

@@ -135,7 +135,7 @@ You have to pass a factory function `func` that returns an NEW instance of an im
135135
>Although I always would recommend using an abstract base class as registration type so that you can vary the implementations you don't have to do this. You can also register concrete types.
136136
137137
```Dart
138-
void registerSingleton<T>(T instance)
138+
void registerSingleton<T>(T instance)
139139
```
140140

141141
You have to pass an instance of `T` or a derived class of `T` that you will always get returned on a call to `get<T>()`.
@@ -145,14 +145,14 @@ As creating this instance can be time consuming at app start-up you can shift th
145145
```Dart
146146
void registerLazySingleton<T>(FactoryFunc<T> func)
147147
```
148-
148+
149149
You have to pass a factory function `func` that returns an instance of an implementation of `T`. Only the first time you call `get<T>()` this factory function will be called to create a new instance. After that you will always get the same instance returned.
150150

151151

152152

153153
### Overwriting registrations
154154
If you try to register a type more than once you will get an assertion in debug mode because normally this is not needed and not advised and probably a bug.
155-
If you really have to overwrite a registration, then you can by setting the property `allowReassignment==true`.
155+
If you really have to overwrite a registration, then you can by setting the property `allowReassignment==true`.
156156

157157
### Testing if a Singleton is already registered
158158
You can check if a certain Type or instance is already registered in GetIt with:
@@ -168,13 +168,13 @@ If you need to you can also unregister your registered singletons and factories
168168

169169
```Dart
170170
/// Unregister a factory/ singletons by Type [T] or by name [instanceName]
171-
/// If its a singleton/lazySingleton you can unregister an existing registered object instance
172-
/// by passing it as [instance]. If a lazysingleton wasn't used before expect
171+
/// If its a singleton/lazySingleton you can unregister an existing registered object instance
172+
/// by passing it as [instance]. If a lazysingleton wasn't used before expect
173173
/// this to throw an `ArgumentError`
174174
/// if you need to dispose any resources you can do it using [disposingFunction] function
175175
/// that provides a instance of your class to be disposed
176176
void unregister<T>({Object instance,String instanceName, void Function(T) disposingFunction})
177-
```
177+
```
178178

179179
### Resetting LazySingletons
180180

@@ -184,8 +184,8 @@ In some cases you might not want to unregister a LazySingleton but instead to re
184184
/// Clears the instance of a lazy singleton registered type, being able to call the factory function on the first call of [get] on that type.
185185
void resetLazySingleton<T>({Object instance,
186186
String instanceName,
187-
void Function(T) disposingFunction})
188-
```
187+
void Function(T) disposingFunction})
188+
```
189189

190190

191191
### Resetting GetIt completely
@@ -218,11 +218,11 @@ Future<T> getAsync<T>([String instanceName]);
218218
```
219219

220220

221-
## Asynchronous Singletons
221+
## Asynchronous Singletons
222222

223-
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.
223+
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.
224224

225-
You create an Singleton with an asynchronous creation function
225+
You create an Singleton with an asynchronous creation function
226226

227227
```Dart
228228
void registerSingletonAsync<T>(FactoryFuncAsync<T> factoryfunc,
@@ -232,7 +232,7 @@ You create an Singleton with an asynchronous creation function
232232
```
233233

234234
The difference to a normal Singleton is that you don't pass an existing instance but provide an factory function
235-
that returns a `Future` that completes at the end of `factoryFunc` and signals that the Singleton is ready to use unless `true` is passed for `signalsReady`. (see next chapter)
235+
that returns a `Future` that completes at the end of `factoryFunc` and signals that the Singleton is ready to use unless `true` is passed for `signalsReady`. (see next chapter)
236236
To synchronize with other "async Singletons" you can pass a list of `Type`s in `dependsOn` that have to be ready before the passed factory is executed.
237237

238238
There are two possible ways to signal the system that an instance is ready.
@@ -271,7 +271,7 @@ If you register any async Singletons `allReady` will complete only after all of
271271
272272
getIt.registerSingletonAsync<RestService>(() async => RestService().init());
273273
// here we asume an async factory function `createDbServiceAsync`
274-
getIt.registerSingletonAsync<DbService>(createDbServiceAsync);
274+
getIt.registerSingletonAsync<DbService>(createDbServiceAsync);
275275
276276
277277
/// ... in your startup page:
@@ -315,17 +315,17 @@ In case that this services have to be initialized in a certain order because the
315315
dependsOn: [ConfigService, DbService, RestService]);
316316
```
317317

318-
When using `dependsOn` you ensure that the registration waits with creating its singleton on the completion of the type defined in `dependsOn`.
318+
When using `dependsOn` you ensure that the registration waits with creating its singleton on the completion of the type defined in `dependsOn`.
319319

320320

321321
### Manually signalling the ready state of a Singleton
322322
Sometimes the mechanism of `dependsOn` might not give you enough control. For this case you can use `isReady` to wait for a certain singelton:
323323

324324
```Dart
325-
/// Returns a Future that completes if the instance of an Singleton, defined by Type [T] or
325+
/// Returns a Future that completes if the instance of an Singleton, defined by Type [T] or
326326
/// by name [instanceName] or by passing the an existing [instance], is ready
327327
/// If you pass a [timeout], an [WaitingTimeOutException] will be thrown if the instance
328-
/// is not ready in the given time. The Exception contains details on which Singletons are
328+
/// is not ready in the given time. The Exception contains details on which Singletons are
329329
/// not ready at that time.
330330
/// [callee] optional parameter which makes debugging easier. Pass `this` in here.
331331
Future<void> isReady<T>({
@@ -339,7 +339,7 @@ Sometimes the mechanism of `dependsOn` might not give you enough control. For th
339339
To signal that it is ready a singleton can use `signalReady` to be able to use that you have to set the optional `signalsReady` parameter when registering it OR make your registration type implement the empty abstract class `WillSignalReady`. In that case `allReady` will wait on a call to signalsReady. No automatic signalling will happen in that case.
340340

341341
```Dart
342-
/// Typically this is used in this way inside the registered objects init
342+
/// Typically this is used in this way inside the registered objects init
343343
/// method `GetIt.instance.signalReady(this);`
344344
void signalReady(Object instance);
345345
```
@@ -385,25 +385,25 @@ In some cases its handy if you could pass changing values to factories when call
385385
/// [instanceName] if you provide a value here your factory gets registered with that
386386
/// name instead of a type. This should only be necessary if you need to register more
387387
/// than one instance of one type. Its highly not recommended
388-
///
388+
///
389389
/// example:
390-
/// getIt.registerFactoryParam<TestClassParam,String,int>((s,i)
390+
/// getIt.registerFactoryParam<TestClassParam,String,int>((s,i)
391391
/// => TestClassParam(param1:s, param2: i));
392-
///
392+
///
393393
/// if you only use one parameter:
394-
///
395-
/// getIt.registerFactoryParam<TestClassParam,String,void>((s,_)
394+
///
395+
/// getIt.registerFactoryParam<TestClassParam,String,void>((s,_)
396396
/// => TestClassParam(param1:s);
397397
void registerFactoryParam<T,P1,P2>(FactoryFuncParam<T,P1,P2> factoryfunc, {String instanceName});
398398
```
399399

400-
and
400+
and
401401

402402
```Dart
403403
void registerFactoryParamAsync<T,P1,P2>(FactoryFuncParamAsync<T,P1,P2> factoryfunc, {String instanceName});
404404
```
405405

406-
The reason why I settled to use two parameters is that I can imagine some scenarios where you might want to register a builder function for Flutter Widgets that need to get passed a `BuildContext` and some data object.
406+
The reason why I settled to use two parameters is that I can imagine some scenarios where you might want to register a builder function for Flutter Widgets that need to get passed a `BuildContext` and some data object.
407407

408408
When accessing these factories you pass the parameters a optional arguments to `get()`:
409409

@@ -457,12 +457,12 @@ If you have a mocked version of a Service you can easily switch between that and
457457
This should only be your last resort as you can loose your type safety and lead the concept of a singleton add absurdum.
458458
This was added following a request at https://github.com/fluttercommunity/get_it/issues/10
459459

460-
Ok you have been warned. All register functions have an optional named parameter `instanceName`. If you provide a value here
460+
Ok you have been warned. All register functions have an optional named parameter `instanceName`. If you provide a value here
461461
your factory/singleton gets registered with that name instead of a type. Consequently `get()` has also an optional parameter `instanceName` to access
462462
factories/singletons that were registered by name.
463463

464-
**IMPORTANT:** Each name for registration can only used once.
465-
Both way of registration are complete separate from each other.
464+
**IMPORTANT:** Each name for registration can only used once.
465+
Both way of registration are complete separate from each other.
466466

467467

468468
### More than one instance of GetIt
@@ -479,4 +479,4 @@ GetIt myOwnInstance = GetIt.asNewInstance();
479479
This new instance does not share any registrations with the singleton instance
480480

481481
## Acknowledgements
482-
Many thanks to the insightful discussions on the API with [Brian Egan](https://github.com/brianegan) and [Simon Lightfoot](https://github.com/slightfoot)
482+
Many thanks to the insightful discussions on the API with [Brian Egan](https://github.com/brianegan) and [Simon Lightfoot](https://github.com/slightfoot)

0 commit comments

Comments
 (0)