Skip to content

Commit b91208f

Browse files
committed
Merge branch 'master' of https://github.com/Flutterando/modular
2 parents bb77838 + b3c851d commit b91208f

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

doc/docs/flutter_modular/dependency-injection.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ sidebar_position: 3
44

55
# Dependency Injection
66

7-
We generally code with maintenance and scalability in mind, applying project-specific patterns
8-
to a given function and improving the structure of our code. We must to pay attention on our code,
9-
otherwise it can be a covertly problem. Let's look at the practical example:
7+
We generally code with maintainability and scalability in mind, applying project-specific patterns
8+
to a given function and improving the structure of our code. We must pay attention to our code,
9+
otherwise it can become a hidden problem. Let's look at a practical example:
1010

1111
```dart
1212
class Client {
@@ -27,7 +27,7 @@ Despite being a simple and functional approach, having a class instance within t
2727
We call it "Dependency Coupling" when we use an outer class in this way, because the *Client* class
2828
is totally dependent on the functioning of the **XPTOEmail** object.
2929

30-
To break a class's bond with its dependency, we generally prefer to "inject" the dependency instances through constructor, setters or methods. That's what we call "Dependency Injection".
30+
To break a class's bond with its dependency, we generally prefer to "inject" the dependency instances through a constructor, setters, or methods. That's what we call "Dependency Injection".
3131

3232
Let's fix the **Customer** class by injecting the **XPTOEmail** instance by constructor:
3333

@@ -42,11 +42,11 @@ class Client {
4242
}
4343
}
4444
```
45-
Thereway, we reduce the coupling **XPTOEmail** object has to the **Client** object.
45+
This way, we reduce the coupling **XPTOEmail** object has to the **Client** object.
4646

4747
We still have a problem with this implementation. Despite *cohesion*, the Client class has a dependency on an external source, and even being injected by constructor, replacing it with another email service would not be a simple task.
48-
Our code still have coupling, but we can improve this using `interfaces`. Let's create an interface
49-
to sign the **sendEmail** method. With this, any class that implements this interface can be injected into the class **Client**:
48+
Our code still has coupling, but we can improve this using `interfaces`. Let's create an interface
49+
to define a signature, or "contract" for the **sendEmail** method. With this in place, any class that implements this interface can be injected into the class **Client**:
5050

5151
```dart
5252
abstract class EmailService {
@@ -170,7 +170,7 @@ We can get the asynchronous instance directly too without having to convert to a
170170
## Auto Dispose
171171

172172
The lifetime of a Bind singleton ends when its module 'dies'. But there are some objects that, by default,
173-
runs by an instance destruction routine and automatically removed from memory. Here they are:
173+
run an instance destruction routine and are automatically removed from memory. Here they are:
174174

175175
- Stream/Sink (Dart Native).
176176
- ChangeNotifier/ValueNotifier (Flutter Native).
@@ -196,24 +196,24 @@ As BLoC is based on Streams, the memory release takes effect automatically.
196196
:::
197197

198198
**flutter_modular** also offers a singleton removal option from the dependency injection system
199-
calling the **Modular.dispose**() method even with a active module:
199+
by calling the **Modular.dispose**() method even with an active module:
200200

201201
```dart
202202
Modular.dispose<MySingletonBind>();
203203
```
204204

205205
## Hot Reload
206206

207-
The modular is hot-reload friendly, but, singleton binds they are not notified.
208-
Use ReassembleMixin for this:
207+
The modular is hot-reload friendly, but, singleton binds are not notified.
208+
Use the ReassembleMixin for this:
209209

210210
```dart
211211
import 'package:flutter_modular/flutter_modular.dart';
212212
213213
class ProductController with ReassembleMixin {
214214
@override
215215
void reassemble() {
216-
//called when happens the hot reload.
216+
//called when the hot reload happens.
217217
print('reassemble');
218218
}
219219
}

flutter_modular/lib/flutter_modular.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export 'package:modular_core/modular_core.dart'
3737
final Modular = injector<IModularBase>();
3838

3939
@visibleForTesting
40-
String initialRouteDeclaratedInMaterialApp = '/';
40+
String initialRouteDeclaredInMaterialApp = '/';
4141

4242
extension ModularExtensionMaterial on MaterialApp {
4343
MaterialApp modular() {
@@ -47,7 +47,7 @@ extension ModularExtensionMaterial on MaterialApp {
4747

4848
injector.get<IModularNavigator>().setNavigatorKey(navigatorKey);
4949

50-
initialRouteDeclaratedInMaterialApp = initialRoute ?? '/';
50+
initialRouteDeclaredInMaterialApp = initialRoute ?? '/';
5151

5252
final app = MaterialApp.router(
5353
key: key,
@@ -95,7 +95,7 @@ extension ModularExtensionCupertino on CupertinoApp {
9595

9696
(injector.get<IModularBase>() as ModularBase).flags.isCupertino = true;
9797

98-
initialRouteDeclaratedInMaterialApp = initialRoute ?? '/';
98+
initialRouteDeclaredInMaterialApp = initialRoute ?? '/';
9999

100100
final app = CupertinoApp.router(
101101
key: key,

flutter_modular/lib/src/presenter/navigation/modular_route_information_parser.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ class ModularRouteInformationParser
3737
if (routeInformation.location == null ||
3838
routeInformation.location == '/') {
3939
// ignore: invalid_use_of_visible_for_testing_member
40-
path = initialRouteDeclaratedInMaterialApp;
40+
path = initialRouteDeclaredInMaterialApp;
4141
} else {
4242
path = routeInformation.location!;
4343
}
4444

4545
_firstParse = true;
4646
} else {
4747
// ignore: invalid_use_of_visible_for_testing_member
48-
path = routeInformation.location ?? initialRouteDeclaratedInMaterialApp;
48+
path = routeInformation.location ?? initialRouteDeclaredInMaterialApp;
4949
}
5050

5151
return await selectBook(path);

0 commit comments

Comments
 (0)