The fact that the .graph scope is assumed by default led me to very confusing results in so far as I did not expect my factories to be called more than once. It took me a while to figure out what was going on, especially because this concept of object scope isn't mentioned anywhere in the README.
It seems to me that .inObjectScope(.container) is the behavior that I have come across in most DI frameworks. Should this be the default instead?
Hi @Herriau. Thanks for posting the issue. Can you make a list of the other DI frameworks that have container (or singleton) scope as default, and graph scope as default for comparison?
If the documentation is the problem, it is linked from README.
https://github.com/Swinject/Swinject/blob/master/Documentation/ObjectScopes.md
Regardless of the existence of that ObjectScopes page, I feel like if .graph is to remain the default, this should be mentioned in big letters on the main README.
I'd add my bit to this thread. I also feel like .graph scope is not what I need in my apps. But also I understand that changing this would semantically be a big breaking change.
But my case is a bit different, my ideal default scope would be .transient. I use SwinjectAutoregistration and almost every factory I register assumes that every object returned is newly created.
My suggestion would be to keep .graph as default scope, but allow developers to change it.
Thanks @olejnjak for your idea馃憤
@yoichitgy I could (try to) create a PR to make the default scope part of the container as a configuration option. What do you think?
Yup, once I realized that .graph is default scope, I had to look at every and each registration place, and explicitly specifying either .container or .transient depending on context.
Spring uses singleton as the default scope. I think, nobody can't say nothing against Spring and its design. So...
Resolved by #304