Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TyphoonFactoryProvider + circular dependencies #191

Closed
jasperblues opened this issue Mar 7, 2014 · 2 comments
Closed

TyphoonFactoryProvider + circular dependencies #191

jasperblues opened this issue Mar 7, 2014 · 2 comments
Labels

Comments

@jasperblues
Copy link
Member

When declaring views in Typhoon, I often wire in the delegate as a circular dependency. However, if using TyphoonFactoryProvider, this doesn't seem possible.

Options:

  • Let TyphoonFactoryProvider support this
  • Discourage wiring delegates this way

Example:

- (id)userProfileViewControllerFactory
{
    return [TyphoonFactoryProvider withProtocol:@protocol(VBUserProfileControllerFactory) dependencies:^(TyphoonDefinition* definition)
    {
        [definition injectProperty:@selector(client)];
        [definition injectProperty:@selector(userProfileView)];
        [definition injectProperty:@selector(title) withObjectInstance:@"Settings"];
    } returns:[VBUserProfileViewController class]];
}

- (id)userProfileView
{
   //Normally delegate property would point back to the view controller. 
    return [TyphoonDefinition withClass:[VBUserProfileView class]];
}

@drodriguez ?

@drodriguez
Copy link
Contributor

Do you have something in mind? I don’t see an automatic way to do it, if you ask me… iterate over all the definitions (currently not available at runtime), and look for a property conforming a protocol our returns: conforms too? (seems to me that it will break more than it will help).

As I see it, you can do it “by hand”:

- (id)userProfileViewControllerFactory
{
    return [TyphoonFactoryProvider withProtocol:@protocol(VBUserProfileControllerFactory) dependencies:^(TyphoonDefinition* definition)
    {
        [definition injectProperty:@selector(client)];
        [definition injectProperty:@selector(userProfileView)];
        [definition injectProperty:@selector(title) withObjectInstance:@"Settings"];
    } factory:^(id<VBUserProfileControllerFactory> factory, id arg1, id arg2) {
      id userProfileView = factory.userProfileView;
      id userProfileViewController = [VBUserProfileViewController initWithClient:factory.client userProfileView:userProfileView title:@"Settings" arg1:arg1 arg2:arg2];
      userProfileView.delegate = userProfileViewController;
      return userProfileViewController;
    }];
}

(if we merge #180, saving the VBUserProfileView in a local variable is important).

We can always augment the API to support the simpler cases (“inject the result into this property of this dependency”), if you think it will be generally useful.

@jasperblues
Copy link
Member Author

You're right. This would be the most sensible way to do it.

Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants