-
Notifications
You must be signed in to change notification settings - Fork 0
1.x_Using assembled components
Block Assembly | Xml Assembly | Autowiring | Using assembled Components | Installing | Configuration-Management-&-Testing
TyphoonComponentFactory componentFactory = [[TyphoonXmlComponentFactory alloc]
initWithConfigFileName:@"MiddleAgesAssembly.xml"];
//or. . .
TyphoonComponentFactory* factory = [[TyphoonBlockComponentFactory alloc]
initWithAssembly:[MiddleAgesAssembly assembly]];
### Resolving by key
The container allows retrieving an instance with its key (if it has one).
Knight* knight = [componentFactory objectForKey:@"knight"];
### Resolving by type
The container allows retrieving an instance with its type (either class or a conforming protocol). Note that multiple objects can match a given protocol and/or class.
Knight* knight = [componentFactory componentForType:[Knight class];
id<Quest> quest = [componentFactory componentForType:@protocol(Quest)];
NSArray* quests = [componentFactory allComponentsForType:@protocol(Quest)];
The container allows injecting properties on a pre-allocated object. This is useful when an object is created by external library code.
Knight* knight = ...
[componentFactory injectProperties:knight];
You can set a component factory as the default factory, so that you can retrieve it for use later. For example, this can be useful when transitioning from one view to another (similar to StoryBoards).
[componentFactory makeDefault];
Later use:
UIViewController* controller = [[TyphoonComponentFactory defaultFactory] componentForType:[MyNextController class]];
//The controller has all of it's collaborators injected, according to it's definition.
//Now do something with the controller. Eg push it to a navigation controller, transition with view, etc.
###Using the Assembly Interface (block-style only)
Knight* knight = [(MiddleAgesAssembly*) factory basicKnight];
MiddleAgesAssembly* assembly = [TyphoonAssembly defaultAssembly];
Knight* knight = [assembly basicKnight];
Something still not clear? How about posting a question on StackOverflow.
Get started in two minutes.
Get familiar with Typhoon.
- [Types of Injections](Types of Injections)
- [What can be Injected](What can be Injected)
- Auto-injection (Objective-C)
- Scopes
- Storyboards
- TyphoonLoadedView
- Activating Assemblies
Become a Typhoon expert.
For contributors or the just plain curious.