-
Notifications
You must be signed in to change notification settings - Fork 269
Activating Assemblies
##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];
Something still not clear? How about posting a question on StackOverflow.
Get started in two minutes.
Get familiar with Typhoon.
- Types of Injections
- What can be Injected
- Auto-injection (Objective-C)
- Scopes
- Storyboards
- TyphoonLoadedView
- Activating Assemblies
Become a Typhoon expert.
For contributors or curious folks.