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

Should issue warning if circular dependent component in initializer #75

Closed
jasperblues opened this issue Sep 12, 2013 · 7 comments
Closed
Labels

Comments

@jasperblues
Copy link
Member

If the the initializer uses that component it will not be in a fully constructed state.

@cesteban
Copy link
Contributor

I believe it should be enough to document this. I mean, in the initializer you shouldn't do any logic other than storing dependencies for later use. That applies in general, but it is specially important when using a DI container. IMHO it should be enough to warn the user that during initialization some injected dependencies might be in an incomplete state. They have afterPropertyInjection for setting up things when no other choice is available.

@jasperblues
Copy link
Member Author

Ok, perhaps we'll just document the behavior, and issue a warning at runtime.

My primary motivation for throwing an exception is to do the same thing as Spring. . . but we don't have to be the same. . In fact, I didn't even know that Spring did this until I checked this morning.

@rhgills
Copy link
Contributor

rhgills commented Sep 12, 2013

I fall on the raise an exception side of things. I think we should be opiniated, and forcing moving to property injection in the case of circular dependencies can prevent subtle bugs. In addition, we shouldn't provide partially initialized dependencies whenever possible. Although I suppose even with property injection, circular dependencies are going to be incomplete when they are being wired up, so you can still do something incorrect in a setter method.

Now I'm talking myself out of my stance. It seems you can hang yourself either way.

@jasperblues
Copy link
Member Author

Thanks for your input @rhgills . . .

What about a post-construct block? Would that help @cesteban ?

Example:

[TyphonDefinition withClass:[Foobar class] initilizer:. .. <normal deps go here> 
    post-construct:^(Foobar* constructedObject)
{
  [foobar setHogwash:xxxxx];
}
];

or even

[TyphonDefinition withClass:[Foobar class] initilizer:. .. <normal deps go here> 
    post-construct:^(Foobar* constructedObject, Assembly* assembly)
{
  [foobar setHogwash:xxxxx];
}
];

@jasperblues
Copy link
Member Author

@rhgills - based on your analysis, we'll go for the warning and allow this.

@rhgills
Copy link
Contributor

rhgills commented Sep 18, 2013

@jasperblues Sounds good.

@jasperblues
Copy link
Member Author

Upon reflection, I think its acceptable if we simply document this.

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

No branches or pull requests

3 participants