injectable icon indicating copy to clipboard operation
injectable copied to clipboard

Can we register module classes under different environments?

Open jamacco94 opened this issue 3 years ago • 3 comments

Is it possible to register a module class under different environments?

Example:

@prod
@dev
@module
abstract class ServicesModule {}

@mock
@module
abstract class ServicesMockModule {}

jamacco94 avatar Aug 15 '22 11:08 jamacco94

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
 }

Milad-Akarie avatar Aug 15 '22 11:08 Milad-Akarie

Thanks @Milad-Akarie

jamacco94 avatar Aug 15 '22 12:08 jamacco94

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.

0ttik avatar Aug 23 '22 07:08 0ttik

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

github-actions[bot] avatar Mar 27 '23 08:03 github-actions[bot]