-
Notifications
You must be signed in to change notification settings - Fork 268
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
Circular Dependencies causes crash #57
Comments
Works if loginView is a singleton |
Ok, for circular dependencies we
We resolve the pre-built component from the singleton cache, so its not going to work for prototypes. We need a temporary cache for prototypes.
|
Probably a dumb question (I didn't follow the STR yet), but: In the definition of loginController, why are you injecting loginView twice? (both in the initializer and by property). |
@cesteban Oops, that was a mistake. . the problem still occurs in any case. |
I'm having similar issues with initializer injection on circular chains of prototypes. Typhoon gets trapped in infinite loop trying to instantiate the same prototype again and again. I think we should register instances in _currentlyResolvingReferences earlier in the building process, right after allocating them. I reorganized the instance builder a little bit and everything seems to work better. I want to carefully test it. If everything goes right, I'll send a pull request. Look forward to hear your thoughts on this. |
Yes, its broken and waiting for a fix. . . I thought I checked and discovered that:
This means that, if its a singleton, it will be ready and waiting for the circular deps to be provided. If its a prototype, getting by key, will kick-off creating a new one again. . . So instead we should put the circulars in a temp cache of their own, ready to retrieve and inject at the last step. We may or may not want to allow multi-threaded access here. If we do, not only would we need a temp-cache, but an additional key to find the object again. . . . I could be wrong here. But I think that's what's going on. |
Ok, I could be missing something, but in my mind the problem appears because in order to build MPLoginController Typhoon does the following:
My solution: mark MPLoginController as currently resolving reference as soon as you have the instance allocated. Makes sense? I want to have time to thoroughly test it, but for the moment is working fine. |
Steps to reproduce:
{
return [TyphoonDefinition withClass:[MPLoginController class] initialization:^(TyphoonInitializer* initializer)
{
initializer.selector = @selector(initWithLoginView:);
[initializer injectWithDefinition:[self loginView]];
} properties:^(TyphoonDefinition* definition)
{
[definition injectProperty:@selector(authorizationUrl) withValueAsText:@"${oauth.authorization.url}"];
[definition injectProperty:@selector(authentication) withDefinition:[self oauthAuthentication]];
[definition injectProperty:@selector(keychainItemName) withValueAsText:@"${oauth.keychain.item.name}"];
[definition injectProperty:@selector(loginView) withDefinition:[self loginView]];
}];
}
{
return [TyphoonDefinition withClass:[MPLoginView class] properties:^(TyphoonDefinition* definition)
{
[definition injectProperty:@selector(delegate) withDefinition:[self loginController]];
}];
}
{
return (MPRootViewController_) [TyphoonDefinition withClass:[MPRootViewController class]
initialization:^(TyphoonInitializer* initializer)
{
initializer.selector = @selector(initWithMainContentViewController:);
[initializer injectWithDefinition:[self loginController]];
} properties:^(TyphoonDefinition* definition)
{
definition.afterPropertyInjection = @selector(mplusInitialization);
}];
}
EXPECTED OUTCOME:
ACTUAL OUTCOME
Causes crash.
The text was updated successfully, but these errors were encountered: