Skip to content

Instantly share code, notes, and snippets.

@RodBr
Created May 28, 2020 09:43
Show Gist options
  • Save RodBr/040e13858937a9102bf66aa67b87e538 to your computer and use it in GitHub Desktop.
Save RodBr/040e13858937a9102bf66aa67b87e538 to your computer and use it in GitHub Desktop.
Inject Dependencies
// 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