Created
May 28, 2020 09:43
-
-
Save RodBr/040e13858937a9102bf66aa67b87e538 to your computer and use it in GitHub Desktop.
Inject Dependencies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Production | |
Get.lazyPut<MyService>(() => MyServiceImpl()); | |
// Test | |
Get.lazyPut<MyService>(() => MyServiceMock()); | |
// Call - same for either Production or Test | |
MyService.to.multiply(count1.value, count.value); | |
abstract class MyService { | |
static MyService get to => Get.find(); | |
int multiply(int val1, int val2); | |
} | |
class MyServiceImpl extends MyService { | |
MyServiceImpl() { | |
print('MyServiceImpl ctor'); | |
} | |
@override | |
int multiply(int val1, int val2) { | |
return val1 + val2; | |
} | |
} | |
class MyServiceMock extends MyService { | |
MyServiceMock() { | |
print('MyServiceMock ctor'); | |
} | |
@override | |
int multiply(int val1, int val2) { | |
return 100; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment