Can we register module classes under different environments?
Is it possible to register a module class under different environments?
Example:
@prod
@dev
@module
abstract class ServicesModule {}
@mock
@module
abstract class ServicesMockModule {}
Hello @jamacco94 This not supported in the current implementation, although I think it might be a good feature but you can easily end up with missing dependencies for multiple environment because it's not clear how we can bind all env implementation to a specific protocol. With the current setup I'd make a facade or a middle class that holds implementations for all the needed dependencies
abstract class MyModule{
Dep1 get dep1;
Dep2 get dep2;
}
@mock
@Injectable(as: MyModule)
class MyModuleMock extends MyModule{
// inject needed dependencies in constructor
}
@prod
@Injectable(as: MyModule)
class MyModuleProd extends MyModule{
// inject needed dependencies in constructor
}
Thanks @Milad-Akarie
Hello @jamacco94 This not supported in the current implementation, although I think it might be a good feature but you can easily end up with missing dependencies for multiple environment because it's not clear how we can bind all env implementation to a specific protocol. With the current setup I'd make a facade or a middle class that holds implementations for all the needed dependencies
abstract class MyModule{ Dep1 get dep1; Dep2 get dep2; } @mock @Injectable(as: MyModule) class MyModuleMock extends MyModule{ // inject needed dependencies in constructor } @prod @Injectable(as: MyModule) class MyModuleProd extends MyModule{ // inject needed dependencies in constructor }
Hello, @Milad-Akarie!
What if I need different dependencies in that modules for different environments? I know that I can leave some dependency to throw UnimplementedError() but it feels better to deal with it with different environments for each module.
My usecase is to provide AndroidDeviceInfo or IosDeviceInfo from device_info_plus library depending on the system.
Also It would resolve a problem with preResolve annotation not having support for an environment parameter.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions