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

Method Injection? #156

Closed
ronak2121 opened this issue Jan 29, 2014 · 4 comments
Closed

Method Injection? #156

ronak2121 opened this issue Jan 29, 2014 · 4 comments

Comments

@ronak2121
Copy link

Hi,

I'm wondering if Typhoon offers a method to do method injection?

Here's what Spring Framework offers in Java:

http://docs.spring.io/spring/docs/4.0.2.BUILD-SNAPSHOT/spring-framework-reference/htmlsingle/#beans-factory-method-injection

If not, I imagine the fallback is to grab a reference to the default TyphoonFactory and get a new object...(there by coupling our code to Typhoon?)

Thanks,

Ronak

@jasperblues
Copy link
Member

@ronak2121

We don't currently have this feature.

Alternatives:

Not coupled directly to Typhoon:

Still dependency injection, but coupled to Typhoon

  • Use TyphoonComponentFactoryAware (can be replaced with a mock during testing).

*Ticket number #131 (coming in a few days) will allow injection of assembly interfaces by type. Still coupled to Typhoon, because these interfaces are a sub-class of TyphoonAssembly, but more domain-specific in that they relate to your app rather than the the TyphoonComponentFactory. (can be replaced with a mock during testing).

Typhoon's default scope:

Note that in Spring the default scope is singleton. This makes sense on a web-server when any given use-case could be invoked at a time. On mobile and desktop we typically serve one use-case at a time, so the default-scope is TyphoonScopeObjectGraph

This scope means that when you resolve a component, any instance that is shared during resolution, will be treated as a singleton.

Eg:

- (id)checkoutFormViewController
{
    ///injected with checkoutView and checkoutViewValidator
}

- (id)checkoutView
{
    //Injected with checkoutViewValidator
}

- (id)checkoutViewValidator
{
    //with ObjectGraph scope, this is treated as a shared instance between 
    //checkoutFormViewController and cehckoutView, but they're not retained by Typhoon, 
    //so when the use-case is done the whole lot goes away. 
}

Because of this difference in default scope, it was recently common to make a view controller TyphoonComponentFactoryAware (as in the sample app), in order to resolve an object graph and move on to the next use-case. However the recommended approach is now:

@jasperblues
Copy link
Member

@ronak2121 Thoughts?

@jasperblues
Copy link
Member

NB: I don't recommend using TyphoonAssistedFactoryProvider for the above kind of thing until issue #145 is fixed.

TyphoonAssistedFactoryProvider is available now, but will be officially endorsed when we release Typhoon v2.0 (in a few weeks).

@jasperblues
Copy link
Member

@ronak2121 closing. . . if you have any further feedback, please raise a new issue (proposed API) or reopen (discuss further).

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