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

Are Lazy properties needed? #203

Closed
alexgarbarev opened this issue Mar 24, 2014 · 5 comments
Closed

Are Lazy properties needed? #203

alexgarbarev opened this issue Mar 24, 2014 · 5 comments

Comments

@alexgarbarev
Copy link
Contributor

I have problems with supporting it when reworking circular dependencies code.

@jasperblues
Copy link
Member

Lots of folks have reported using them. But it would probably be fair enough to not support them in combination with lazy.

@alexgarbarev
Copy link
Contributor Author

I changed internal API for property and parameter injections, now both used via method:

- (void)valueToInjectWithContext:(TyphoonInjectionContext *)context completion:(TyphoonInjectionValueBlock)result;

I had problem with creation lazyValues, used in TyphoonAssistedFactoryBase, because new API assume that value returned asyncronically (after resovling circular dependencies).

Finally I got:

- (void)doPropertyInjectionIfNeededOn:(id <TyphoonIntrospectiveNSObject, TyphoonPropertyInjectionInternalDelegate>)instance property:(id <TyphoonPropertyInjection>)property
                                 args:(TyphoonRuntimeArguments *)args
{
    if ([instance respondsToSelector:@selector(shouldInjectProperty:withType:lazyValue:)]) {
        TyphoonTypeDescriptor *propertyType = [instance typhoon_typeForPropertyWithName:property.propertyName];

        TyphoonPropertyInjectionLazyValue lazyValue = ^id {
            TyphoonInjectionContext *context = [[TyphoonInjectionContext alloc] init];
            context.destinationType = propertyType;
            context.factory = self;
            context.args = args;
            context.raiseExceptionIfCircular = YES;
            __block id result = nil;
            [property valueToInjectWithContext:context completion:^(id value) {
                result = value;
            }];
            return result;
        };

        if ([instance shouldInjectProperty:property withType:propertyType lazyValue:lazyValue]) {
            [self doPropertyInjection:instance property:property args:args];
        }
    } else {
        [self doPropertyInjection:instance property:property args:args];
    }
}

So, if lazyValue has circular dependency, exceptions will be raised. Is it ok?
@drodriguez can you verify new code? Is old code works fine with circular dependency?

@drodriguez
Copy link
Contributor

I didn’t understand at first what “lazy” properties you meant. I will try to have a look at them later. But I don’t think I implemented them with circular dependencies in mind.

@alexgarbarev
Copy link
Contributor Author

I think you used it when user fills TyphoonAssistedFactoryBase with property injections - to not resolve properties which user not used in future

@jasperblues
Copy link
Member

'lazy simply meant 'Don't instantiate signletons until they're asked for'
. . we can expand the meaning is long as its compatible with the original
meaning.

On Tue, Mar 25, 2014 at 4:00 AM, Aleksey Garbarev
[email protected]:

I think you used it when user fills TyphoonAssistedFactoryBase with
property injections - to not resolve properties which user not used in
future

Reply to this email directly or view it on GitHubhttps://github.com//issues/203#issuecomment-38551558
.

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

3 participants