Skip to content

Propagating runtime arguments

Jasper Blues edited this page May 2, 2014 · 13 revisions

#Propagating run-time arguments through to dependencies

We can propagate a runtime argument through to a dependency as shown:

- (id)loyaltyManagementControllerWithLoyaltyAccounts;
{
    return [TyphoonDefinition withClass:[LoyaltyManagementViewController class] configuration:^(TyphoonDefinition* definition)
    {
        [definition useInitializer:@selector(initWithLoyaltyClient:view:) parameters:^(TyphoonMethod* initializer)
        {
            [initializer injectParameterWith:[_networkComponents loyaltyClient]];
            [initializer injectParameterWith:[self loyaltyManagementViewWithAccounts:loyaltyAccounts]];
        }];
    }];
}

- (id)loyaltyManagementViewWithAccounts:(NSArray*)loyaltyAccounts
{
    return [TyphoonDefinition withClass:[LoyaltyManagementView class] configuration:^(TyphoonDefinition* definition)
    {
        //The loyaltyAccounts parameter is propagated through the parent controller onto the view
        [definition injectMethod:@selector(setLoyaltyAccounts:) parameters:^(TyphoonMethod* method)
        {
            [method injectParameterWith:loyaltyAccounts];
        }];
}

Using runtime arguments with circular dependencies