TyphoonComponentFactory

Objective-C

@interface TyphoonComponentFactory : NSObject {
  NSMutableArray *_registry;
  id<TyphoonComponentsPool> _singletons;
  id<TyphoonComponentsPool> _objectGraphSharedInstances;
  id<TyphoonComponentsPool> _weakSingletons;
  TyphoonCallStack *_stack;
  NSMutableArray *_factoryPostProcessors;
  NSMutableArray *_componentPostProcessors;
  BOOL _isLoading;
}

Swift

class TyphoonComponentFactory : NSObject

@ingroup Factory

This is the base class for all component factories. It defines methods for retrieving components from the factory, as well as a low-level API for assembling components from their constituent parts. This low-level API could be used as-is, however its intended to use a higher level abstraction such as TyphoonBlockComponentFactory.

  • Undocumented

    Declaration

    Objective-C

    NSMutableArray *_registry
  • Undocumented

    Declaration

    Objective-C

    id <TyphoonComponentsPool> _singletons
  • Undocumented

    Declaration

    Objective-C

    id <TyphoonComponentsPool> _objectGraphSharedInstances
  • Undocumented

    Declaration

    Objective-C

    id <TyphoonComponentsPool> _weakSingletons
  • Undocumented

    Declaration

    Objective-C

    TyphoonCallStack *_stack
  • Undocumented

    Declaration

    Objective-C

    NSMutableArray *_factoryPostProcessors
  • Undocumented

    Declaration

    Objective-C

    NSMutableArray *_componentPostProcessors
  • Undocumented

    Declaration

    Objective-C

    BOOL _isLoading
  • The instantiated singletons.

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly) NSArray *singletons;

    Swift

    var singletons: [Any]! { get }
  • Say if the factory has been loaded.

    Declaration

    Objective-C

    @property (nonatomic, getter=isLoaded) BOOL loaded;

    Swift

    var isLoaded: Bool { get set }
  • The attached factory post processors.

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly) NSArray *factoryPostProcessors;

    Swift

    var factoryPostProcessors: [Any]! { get }
  • The attached component post processors.

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly) NSArray *componentPostProcessors;

    Swift

    var componentPostProcessors: [Any]! { get }
  • Returns the default component factory, if one has been set. - see: [TyphoonComponentFactory makeDefault]. This allows resolving components from the Typhoon another class after the container has been set up.

    A more desirable approach, if possible - especially for a component that is also registered with the container is to use TyphoonComponentFactoryAware, which injects the component factory as a dependency on the class that needs it. This latter approach simplifies unit testing, in that no special approach to patching out the classes collaborators is required.

    See

    [TyphoonComponentFactory makeDefault].

    See

    TyphoonComponentFactoryAware

    Declaration

    Objective-C

    + (id)defaultFactory;

    Swift

    class func defaultFactory() -> Any!
  • Undocumented

    Declaration

    Objective-C

    + (void)setFactoryForResolvingFromXibs:(TyphoonComponentFactory *)factory;

    Swift

    class func setFactoryForResolvingFromXibs(_ factory: TyphoonComponentFactory!)
  • Factory used to resolve definition from TyphoonLoadedView.

    Declaration

    Objective-C

    + (TyphoonComponentFactory *)factoryForResolvingFromXibs;

    Swift

    class func forResolvingFromXibs() -> TyphoonComponentFactory!
  • Mutate the component definitions and build the not-lazy singletons.

    Declaration

    Objective-C

    - (void)load;

    Swift

    func load()
  • Dump all the singletons.

    Declaration

    Objective-C

    - (void)unload;

    Swift

    func unload()
    • from the Typhoon another class after the container has been set up. *
    • This method is only integrating Typhoon into legacy environments - classes not managed by Typhoon, and its use elsewhere is discouraged
    • as it will create a hard-wired dependency on Typhoon, whenever the default factory is retrieved. *
    • A more desirable approach is to use TyphoonComponentFactoryAware or to inject the factory via an assembly. This simplifies unit testing. *
    • ## Alternative approach: inject the factory (in this case posing behind a TyphoonAssembly subclass):
    
    - (id)loyaltyManagementController
    {
        return [TyphoonDefinition withClass:[LoyaltyManagementViewController class]
            properties:^(TyphoonDefinition* definition)
        {
            definition.scope = TyphoonScopePrototype;
            //Inject the TyphoonComponentFactory posing as an assembly
            [definition injectProperty:@selector(assembly)];
        }];
    }
    
    
    • - see: [TyphoonComponentFactory makeDefault].
    • - see: TyphoonComponentFactoryAware *

    Declaration

    Objective-C

    - (void)makeDefault;

    Swift

    func makeDefault()
  • Registers a component into the factory. Components can be declared in any order, the container will work out how to resolve them.

    Declaration

    Objective-C

    - (void)registerDefinition:(TyphoonDefinition *)definition;

    Swift

    func register(_ definition: TyphoonDefinition!)
    • @exception NSInvalidArgumentException When no singletons or prototypes match the requested type.
    • @exception NSInvalidArgumentException When when more than one singleton or prototype matches the requested type. *
    • - warning: componentForType with a protocol argument is not currently supported in Objective-C++. *
    • @see: allComponentsForType:

    Declaration

    Objective-C

    - (id)componentForType:(id)classOrProtocol;

    Swift

    func component(forType classOrProtocol: Any!) -> Any!
  • Returns an array objects matching the given type.

    See

    componentForType

    Declaration

    Objective-C

    - (NSArray *)allComponentsForType:(id)classOrProtocol;

    Swift

    func allComponents(forType classOrProtocol: Any!) -> [Any]!
  • Returns the component matching the given key. For the block-style, this is the name of the method on the TyphoonAssembly interface, although, for block-style you’d typically use the assembly interface itself for component resolution.

    Declaration

    Objective-C

    - (id)componentForKey:(NSString *)key;

    Swift

    func component(forKey key: String!) -> Any!
  • Undocumented

    Declaration

    Objective-C

    - (id)componentForKey:(NSString *)key args:(TyphoonRuntimeArguments *)args;

    Swift

    func component(forKey key: String!, args: TyphoonRuntimeArguments!) -> Any!
  • Undocumented

    Declaration

    Objective-C

    - (NSArray *)registry;

    Swift

    func registry() -> [Any]!
  • Undocumented

    Declaration

    Objective-C

    - (void)enumerateDefinitions:(void(^)(TyphoonDefinition *definition, NSUInteger index, TyphoonDefinition **definitionToReplace, BOOL *stop))block;

    Swift

    func enumerateDefinitions(_ block: ((TyphoonDefinition?, UInt, AutoreleasingUnsafeMutablePointer<TyphoonDefinition?>?, UnsafeMutablePointer<ObjCBool>?) -> Void)!)
  • Attach a TyphoonComponentFactoryPostProcessor to this component factory.

    Declaration

    Objective-C

    - (void)attachPostProcessor:(id<TyphoonDefinitionPostProcessor>)postProcessor;

    Swift

    func attach(_ postProcessor: (any TyphoonDefinitionPostProcessor)!)

    Parameters

    postProcessor

    The post-processor to attach.

  • Injects the properties and methods of an object

    Declaration

    Objective-C

    - (void)inject:(id)instance;

    Swift

    func inject(_ instance: Any!)
  • Injects the properties and methods of an object, described in definition

    Declaration

    Objective-C

    - (void)inject:(id)instance withSelector:(SEL)selector;

    Swift

    func inject(_ instance: Any!, with selector: Selector!)

InstanceBuilder