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

injectProperty:(SEL) analog for TyphoonMethod. injectParameter? #336

Closed
fatuhoku opened this issue Apr 9, 2015 · 1 comment
Closed

injectProperty:(SEL) analog for TyphoonMethod. injectParameter? #336

fatuhoku opened this issue Apr 9, 2015 · 1 comment

Comments

@fatuhoku
Copy link
Contributor

fatuhoku commented Apr 9, 2015

Suppose we have a class FooBar, which has a private property quux. Right now, it's possible to say:

[TyphoonDefinition withClass:[FooBar class] configuration:^(TyphoonDefinition *definition) {
    [definition injectProperty:@selector(quux)];
}];

Good. I expect Typhoon to find me some instance of quux and resolve things for me. I have no idea where I'll get my quux. But I've expressed that one is required. This is good behaviour for modules because the app will not run if no suitable instance of quux was found in any of the activated assemblies.

But, if I want to use a specific initialiser instead of using [[FooBar alloc] init], I'm out of luck:

[TyphoonDefinition withClass:[FooBar class] configuration:^(TyphoonDefinition *definition) {
    [definition useInitializer:@selector(initWithQuux:) parameters:^(TyhpoonMethod *initializer){
        [initializer injectParameter:  ??????  ];  // !!!!!!!!!!
    }];
}];

I'm forced to introduce parameter for quux to make it a runtime argument (not desired; I don't want this to be used as a factory method).

Surely there should be analog. i.e. perhaps there should be a version of injectParameter that just doesn't accept any parameters, which actually resolves the component from all activated assemblies and barfs if it doesn't find it, just like injectProperty:(SEL) would.

@jasperblues
Copy link
Member

initializer and method injections don't have to be runtime arguments. Inject with another definition (as shown in the quick start) or any of the options in the section "What Can Be Injected"

Whatever the case it must be explicit, auto injection is not supported. This is because the Objective-C runtime doesn't provide type information for method or initializer parameters, only for properties.

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