-
Notifications
You must be signed in to change notification settings - Fork 268
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 new] 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: [Injecting assemblies themselves](What can be Injected#injecting-the-assembly-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.
MiddleAgesAssembly *assembly = [[MiddleAgesAssembly new] activate];
Knight* knight = ... //Obtained from somewhere
[assembly inject:knight]; //Matches by type
[assembly inject:knight withSelector:@selector(selectorInAssembly)];
#Default Assembly
Its possible to set an instance of TyphoonAssembly
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
TyphoonAssembly
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 TyphoonAssembly as a dependency on an object that will proceed to another object graph). - Getting a hook to the instance of
TyphoonAssembly
that the app is using from test cases.
TyphoonAssembly *assembly; //Some active assembly
[assembly makeDefault];
NB: Activated assemblies are actually an instance of TyphoonComponentFactory
posing as an assembly. This means if you instantiated Typhoon with three assemblies, then defaultAssembly
can be cast to any of these assemblies.
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.