I also don't fully understand scopes. I defined a ...
# kotlin-inject
a
I also don't fully understand scopes. I defined a scope annotation, say @MainWindowScope and annotated my injection component. Do I need to annotate all the classes where I want to reuse the same instance with @MainWindowScope? I'm kinda confused how that works.
f
you don't need to annotate all the classes using the scoped dependency by default, every time you get a dependency from a component you're getting a new object — when you annotate a dependency with a scope annotation it simply ensures you'll always get the same object instead (as long as you're keeping the component around, a new component will give you a new object)
a
(as long as you're keeping the component around, a new component will give you a new object)
Thank you for your reply! I guess I'm a little confused by this, as I thought the point of DI is to be able to get the same object instance without having to pass the object around my data model tree. I understand better how this works though, so thanks!
d
DI is also taking care of the wiring of classes, if you need 4 classes in a constructor, DI instantiates and provides them to it... you need to decide if you always want the same instances injected or not, but you don't have to worry about constructing all those objects.