-
Notifications
You must be signed in to change notification settings - Fork 268
Quick Start
jasperblues edited this page Dec 25, 2014
·
49 revisions
Setting up a Dependency Injection container couldn't be more easy.
First, create a sub-class of TyphoonAssembly as follows:
@interface MiddleAgesAssembly : TyphoonAssembly
- (Knight*)basicKnight;
- (Knight*)cavalryMan;
- (id<Quest>)defaultQuest;
@end
Add the method names in the header. This will allow compile-time checking and IDE code-completion. Now simply define the components:
###Perform an Initializer Injection
- (Knight*)basicKnight
{
return [TyphoonDefinition withClass:[Knight class]
configuration:^(TyphoonDefinition* definition)
{
[definition useInitializer:@selector(initWithQuest:)
parameters:^(TyphoonMethod *initializer) {
[initializer injectParameterWith:[self defaultQuest]];
}];
}];
}
- (id<Quest>)defaultQuest
{
return [TyphoonDefinition withClass:[CampaignQuest class]];
}
###Resolve the component from the container as follows:
TyphoonComponentFactory* factory = [[TyphoonBlockComponentFactory alloc]
initWithAssemblies:@[
[MiddleAgesAssembly assembly]
]];
//Code-completion + no 'magic strings'
Knight* knight = [(MiddleAgesAssembly*) factory basicKnight];
And we're done!
- Having obtained our initial component we can proceed from one object graph to another, by injecting the assembly.
- We can have our initial component(s) injected into our app's delegate using plist integration
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.