Skip to content
jasperblues edited this page Dec 23, 2014 · 30 revisions

[Types of Injections](Types of Injections) | [What can be Injected](What can be Injected) | Modularizing Assemblies | Scopes | Activating Assemblies | Storyboards | [Integration Testing](Integration Testing)

Typhoon provides the following scopes:

##TyphoonScopeObjectGraph (default)

This scope means that when a TyphoonDefinition is assembled, any dependencies will be treated as shared instances during assembly. Once resolution is complete they are not retained by Typhoon. This allows instantiating an entire object graph, for a use-case (say for a ViewController), and then discarding it when that use-case has completed.

##TyphoonScopePrototype

Indicates that a new instance should always be created by Typhoon, whenever specified as a dependency to another definition.

##TyphoonScopeSingleton

Indicates that Typhoon should retain the instance effectively creating a singleton, at least as long as the TyphoonComponentFactory that holds it remains.

##TyphoonScopeLazySingleton

This scope behaves the same as TyphoonScopeSingleton, but the object is not created unless or until it is needed.

##TyphoonScopeWeakSingleton

Indicates that a shared instance should be created as long as necessary. When your application's classes stop referencing this component it will be deallocated until needed again.

#Setting Scope:

- (RootViewController *)rootController
{
    return [TyphoonDefinition withClass:[RootViewController class] configuration:^(TyphoonDefinition* definition)
    {
        definition.scope = TyphoonScopeSingleton;
    }];
}