Typhoon - introduces the same instance everywhere

I have a class A that is being injected in several places. I would like to inject the same instance of A everywhere - sort of Singleton but with injection.

Is it possible to do this with Typhoon

+3


source to share


1 answer


Typhoon has three scopes that you can use to do this, TyphoonScopeSingleton , TyphoonScopeLazySingleton, and TyphoonScopeWeakSingleton .

To set the scope of a component:

- (PFRootViewController *)rootViewController
{
    definition.scope = TyphoonScopeSingleton;
}

      

Using this area gives all the advantages of a singlet, while the DI pattern avoids the disadvantages.



More about typhoon clouds:

Many DI containers in other languages ​​have a default scope as singleton , whereas Typhoon has a default scope TyphoonScopeObjectGraph

. Having a singleton scope matters for server environments where an application can serve any use case at a given time.

Typhoon, meanwhile, is geared towards mobile and desktop environments, so the object graph scope is for loading an assembly into memory (example view controller) and then discarding it after switching to another use case. Any shared references, such as a circular dependency pointing to a parent (such as a delegate), will be shared.

Of course, although this is the default, there are times when other scopes are needed. More information can be found in the scope section of the user manual .

+2


source







All Articles