injecting singletons using typhoon giving multiple instance

110 Views Asked by At

I have assembly as follows and it will initiate from plist

@implementation classAAssembly
- (id)classA {
    return [TyphoonDefinition withClass:[classA class] configuration:^(TyphoonDefinition *definition) {
               definition.scope = TyphoonScopeSingleton;
           }];
}

when app load this creates instance and inject into relevant places

then I have some static methods need to use this, so I tried as bellow

+ (void)staticMethod {
      classAAssembly *assembly = [[classAAssembly new] activate];
      classA *classA = [assembly classA];
}

issue is when i do this it gives new instance, what i expecting is same instance created when app load.

any help would be appreciated.

1

There are 1 best solutions below

1
Jasper Blues On

You're creating a new assembly above. What you need to do is get a handle to the one created using plist integration. So for example to access the assembly from your app delegate, inject it into that.

To access the assembly from a static method, you'll have to create a static pointer to it:

- (void) typhoonDidInject {
    myStaticAssembly = this.assembly
}