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

Injecting an object returned by a TyphoonTypeConverter #353

Closed
rwbutler opened this issue May 18, 2015 · 4 comments
Closed

Injecting an object returned by a TyphoonTypeConverter #353

rwbutler opened this issue May 18, 2015 · 4 comments

Comments

@rwbutler
Copy link

I have a plist as follows defining a mapping to a custom object:

<dict>
<key>myObject</key>
<string>MyObject()</string>
<key>myObject.myURL</key>
<string>NSURL(http://myurl.com )</string>
</dict>

It seems that on implementing the TyphoonTypeConverter protocol, only a concrete object can be returned from the convert method rather than another TyphoonDefinition. Is there any way to inject the custom object returned from the TyphoonTypeConverter with another property defined in the plist?

e.g. the MyObject returned by the TyphoonTypeConverter implementation would have a property myURL set to the value defined in the plist?

@jasperblues
Copy link
Member

Yes only a custom object. When you create definitions in a TyphoonAssembly subclass to thing happen:

  • It is instrumented so that each definition is allocated a key. (To support code completion and refactoring without any special tool support).
  • Upon activation the definition is registered with a TyphoonComponentFactory.

So if you wanted a type converter to return a TyphoonDefinition those steps would need to happen too.

@rwbutler
Copy link
Author

Thanks for the info. If I drop the plist mapping and configure in the assembly e.g.

-(ViewController *)viewController {

return [TyphoonDefinition withClass:[DataManager class] configuration:^(TyphoonDefinition *definition)     {
    [definition injectProperty:@selector(dataManager) with:[self dataManager]];
}];
}

Is there a way to inject properties into the dataManager which is already being injected into the view controller?

@jasperblues
Copy link
Member

Yes of course. The definition for the data manager can have initializer, property or method injections. And the injections can be any of these - references to other definitions, scalar values (int, BOOL, etc), inline objects or something resolved from TyphoonConfig.

@jasperblues
Copy link
Member

Let's continue this chat on StackOverflow! http://stackoverflow.com/questions/tagged/typhoon

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

No branches or pull requests

2 participants