Skip to content

Activating Assemblies

Jasper Blues edited this page Feb 14, 2015 · 11 revisions

##Before activation . . .

  • Assemblies return instances of TyphoonDefinition

##Activation is done by either . . .

##After activation . . .

Assemblies return instances built according to the relationships, configuration and scopes that the assembly describes.

MiddleAgesAssembly *assembly = [MiddleAgesAssembly assembly];
[[TyphoonAssemblyActivator withAssemblies:@[assembly]] activate];
Knight* knight = [assembly basicKnight]; 

We can proceed from one object graph to another, by injecting the assembly.

[definition injectProperty:@selector(assembly) with:self];

And now, somewhere in your app:

SignUpViewController* controller = [self.assembly signUpViewController];
//or perhaps with arguments
WelcomeViewController* welcomeViewController = [self.assembly welcomeViewControllerWithUser:user];

See also: [Typhoon Injects Itself](What can be Injected#injecting-typhoon-itself), [run-time arguments](Types of Injections#injection-with-run-time-arguments)



#Instructing Typhoon to Inject a Pre-obtained Instance

The container allows injecting properties on a pre-allocated object, using pre-defined configurations in an assembly. This is useful when an object is created by external library, such as Core Data or your network client, giving "rich" domain objects.

Knight* knight = ...
[componentFactory inject:knight]; //Matches by type
[componentFactory inject:knight withDefinition:@selector(selectorInAssembly)];


#Default Factory

Its possible to set an instance of TyphoonComponentFactory into a static / global context. While we don't normally recommend this, it can be useful int the following situations:

  • Incorporating Typhoon into a legacy application, where we need to get in instance of TyphoonComponentComponentFactory in order in order to obtain a built instance of a class and its dependencies. (In a fully Typhoon powered application we can just inject the dependency or inject the TyphoonComponentFactory).
  • Getting a hook to the instance of TyphoonComponentFactory that the app is using from test cases.
TyphoonComponentFactory *factory;
[factory makeDefault];