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

Dependency injection for objects not emmitted from component factory? #103

Closed
jasperblues opened this issue Nov 16, 2013 · 8 comments
Closed

Comments

@jasperblues
Copy link
Member

I'm thinking of supporting something like Spring's "@configurable" annotation that allows dependency injection of an object that gets instantiated outside of the Typhoon component factory?

This is useful in the following kinds of scenarios:

  • When looking up controllers via a StoryBoard
  • When looking up fat (ie non-aneamic) model objects from a persistent storage.

Of course there are always workarounds - such as providing an injector on DAO object or using the injectWithDependencies hook after resolving from a story board. . . but would this be a nice feature?

I'm thinking of a global:

[MyModelOrControllerClass configureWithFactory:someFactoryOrAssembly]; 

and from their on in, any instantiation of this class would have dependencies injected. . . I guess these would have to use property injection.

Thoughts? Worth it?

@ratkins
Copy link

ratkins commented Nov 25, 2013

We need something that's kind of the other way around.

Using Storyboards (via this technique), UIStoryboard instantiates an instance of our HomeScreenViewController and Typhoon injects its properties.

But we have other objects in our Typhoon assemblies that need access to the navigationViewController property of the HomeScreenViewController that Storyboards created for us. There's no way to tell Typhoon, "Hey, when anybody asks for a UINavigationController, give 'em this instance".

@jasperblues
Copy link
Member Author

The other way around is pretty simple actually. . . We can just use the UIStoryBoard as a factory for emitting other objects. . I will set up an example in the next 24 hours.

@ratkins
Copy link

ratkins commented Nov 26, 2013

It's a little trickier than you may think: we've solved it by introducing a Typhoon-managed proxy object that returns (UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController; it needs to be a proxy as the rootViewController isn't set when Typhoon is doing its thing (the UIStoryBoard hasn't created/wired it up yet.)

@jasperblues
Copy link
Member Author

Sounds simple enough to me. . want to contribute that back?

@ratkins
Copy link

ratkins commented Nov 26, 2013

It's literally that line of code wrapped up in a class. I'll write it up as a gist to illustrate the technique if you like. It still feels like a nasty workaround to me though.

@jasperblues
Copy link
Member Author

Sure that would be helpful. . . meanwhile are you asking about having StoryBoard produced objects to participate as components in the Typhoon assembly? I have some other ideas there. . .

@ratkins
Copy link

ratkins commented Nov 26, 2013

Gistified. And yeah, that's what I'm interested in.

(It may turn out to be that I'm wanting to do something that I shouldn't want to do, too...)

@jasperblues
Copy link
Member Author

Closing in favor of more clearly defined #206

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

No branches or pull requests

2 participants