Skip to content

1.x_Using assembled components

Jasper Blues edited this page Apr 26, 2014 · 3 revisions

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)];


Injecting properties on pre-allocated objects

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];


Making a component factory the default

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];

githalytics.com alpha

Quick Start!

Get started in two minutes.

Main Track

Get familiar with Typhoon.

Advanced Topics

Become a Typhoon expert.

Under the Hood

For contributors or the just plain curious.

Clone this wiki locally