-
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
Should issue warning if circular dependent component in initializer #75
Comments
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. |
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. |
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. |
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];
}
]; |
@rhgills - based on your analysis, we'll go for the warning and allow this. |
@jasperblues Sounds good. |
Upon reflection, I think its acceptable if we simply document this. |
If the the initializer uses that component it will not be in a fully constructed state.
The text was updated successfully, but these errors were encountered: