All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Groups Pages
Assembly

Assembling an application from key collaborators and configuraiton. More...

Classes

class  TyphoonAssembly
 Provides a concise way to declare and encapsulate the architecture of an application in one or more classes that describe how components collaborate together. More...
 
class  TyphoonComponentFactory
 This is the base class for all component factories. More...
 
protocol  <TyphoonComponentFactory>
 Defines a protocol for resolving built instances, injecting a pre-obtained instance using a factory containing definitions from one or more TyphoonAssembly classes. More...
 
protocol  <TyphoonDefinitionPostProcessor>
 Allows for custom modification of a component factory's definitions. More...
 

Functions

(void) - NSObject(FactoryHooks)::typhoonSetFactory:
 Implementation of method typhoonSetFactory indicates that a component wishes to be aware of the TyphoonComponentFactory in order to resolve another component. More...
 
(void) - NSObject(FactoryHooks)::typhoonWillInject
 Typhoon components can implement this methods to participate in property-injection life-cycle events. More...
 

Detailed Description

Assembling an application from key collaborators and configuraiton.

Function Documentation

- (void) typhoonSetFactory: (id)  theFactory

Implementation of method typhoonSetFactory indicates that a component wishes to be aware of the TyphoonComponentFactory in order to resolve another component.

Typically we'd want to inject all the dependencies, however there are some cases where its desirable to load a component from the factory at runtime. One example is view controller transitions where a given view controller has:

  • All of the dependencies for its main use-case injected
  • Looks up the view controller for a transition from the container. This allows using prototype scope to load one object-graph at a time, thus making efficient use of memory. Accepts the TyphoonComponentFactory via setter-injection, allowing the factory to be stored to a property or ivar. Note that this method contract uses the type id, which if you're using a block-style assembly allows setting the factory to the TyphoonAssembly sub-class itself without casting. The underlying type is TyphoonComponentFactory.

Examples:

//Using the TyphoonComponentFactory interface:
- (void)typhoonSetFactory:(TyphoonComponentFactory*)factory
{
_factory = factory;
MyAnalyticsService* service = [factory componentForType:[MyAnalyticsService class];
}
//Using an Assembly interface
- (void)typhoonSetFactory:(MyAssemblyType*)assembly
{
_assembly = assembly;
MyAnalyticsService* service = [assembly analyticsService];
}
Note
Whether the factory is injected as a TyphoonComponentFactory or a TyphoonAssembly sub-class, it can still be casted from one to the other.
- (void) typhoonWillInject

Typhoon components can implement this methods to participate in property-injection life-cycle events.

This gives some of the benefits of initializer-injection - the ability to provide before / after validation - while still allowing the flexibility of property injection.

Note
If you don't wish to implement these methods on your class, you can also define custom callback selectors on TyphoonDefinition.
See also
TyphoonDefinition.beforeInjections
TyphoonDefinition.afterInjections Typhoon calls this method (if implemented) just before property and method injections