SBBComponentManager Class Reference

Inherits from NSObject
Declared in SBBComponentManager.h
SBBComponentManager.m

Overview

This class provides a central point for managing singleton components, to simplify use of dependency injection in the default case, when needing runtime selection between two or more implementations, and mocking for testing.

In general, you should access all such components through this class, either via the component: class method or one of the convenience macros SBBComponent(class) or SBBTestComponent(testClass, class).

+ registerComponent:forClass:

Register a specific component instance to be returned by requests for components registered to a given class.

+ (id)registerComponent:(id)componentInstance forClass:(Class)componentClass

Parameters

componentInstance

The component instance to register for the given componentClass.

componentClass

The class for which to register the given component.

Return Value

The component instance, if any, previously registered for the given componentClass.

Discussion

This method can be used both for registering mock components for testing purposes, and for handling the case where you need to choose one of two or more alternative implementations at runtime based on criteria not available at compile time.

Declared In

SBBComponentManager.h

+ component:

Return the registered instance of the component for the given class.

+ (id)component:(Class)componentClass

Parameters

componentClass

The class for which to get (or instantiate and register) the registered component instance.

Return Value

The registered instance for the given componentClass, or nil if the study has not yet been set up.

Discussion

If the study has not yet been set up (the shared SBBBridgeInfo object’s studyIdentifier is nil), this method will return nil for all components to prevent premature registration of defaults.

If no instance is registered, and componentClass implements the SBBComponent protocol, this method will call the class’s defaultComponent: class method and register the returned value as the instance for the class.

Declared In

SBBComponentManager.h

+ reset

Clear all registered components and start fresh. Used for unit testing.

+ (void)reset

Declared In

SBBComponentManager.h