injectable icon indicating copy to clipboard operation
injectable copied to clipboard

Scope Support

Open AndyDavidJoyce opened this issue 3 years ago • 7 comments

Hi!

Im looking at using injectable, however, one feature that that i need to use that I have not seen mentioned in the documentation is scopes. Is this currently supported by injectable?

AndyDavidJoyce avatar Mar 23 '21 23:03 AndyDavidJoyce

Hey! @AndyDavidJoyce, I didn't get the chance to play with scopes yet, could you show me a brief example on how you're using them manually?

Milad-Akarie avatar Mar 24 '21 08:03 Milad-Akarie

Sample Test here

A brief explanation is here

Perhaps a brief API could look like:

@injectable(scope: 'account_scope')
class ApiClient {
    static Future<ApiClient> create(Deps ...) async {  

and when getIt.pushScope('account_scope') is called, these registrations could happen.

Something along the lines of Hilt - the scoped component based DI framework for Android.

creativepsyco avatar Jun 16 '21 16:06 creativepsyco

Hi! Any news about the issue? Actually, the di config code won't become more difficult:

_i1.GetIt $initGetIt(_i1.GetIt get,
    {String? environment, _i2.EnvironmentFilter? environmentFilter}) {
  final gh = _i2.GetItHelper(get, environment, environmentFilter);
  
  get.onScopeChanged = (pushed) {
    if(pushed) {
      switch(get.currentScopeName) {
        case "scope1":
          // register all "scope1" dependencies 
          // ...
          break;
        case "scope2":
          // register all "scope2" dependencies 
          // ...
          break;
      }
    }
  };
  
  // register all default dependencies
  // ...
  return get;
}

alexander-shustanov avatar Aug 24 '21 05:08 alexander-shustanov

I just knew about the onScopeChange callback, that makes things easier.. I'll try to implement this feature as soon as possible.

Milad-Akarie avatar Aug 25 '21 21:08 Milad-Akarie

Hi. Any news about this? Would be really great to have this feature.

jtdLab avatar Dec 05 '21 21:12 jtdLab

I'm just waiting for this feature to integrate injectable in my company's mobile app. @Milad-Akarie, I'm happy to wait as long you need!!!

fdelucchijr avatar Dec 06 '21 03:12 fdelucchijr

+1

elias8 avatar Mar 20 '22 21:03 elias8

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 Feb 25 '23 08:02 github-actions[bot]