Closed guidoschmidt closed 6 years ago
Interesting. I mainly got inspired by the Spring documentation regarding different types of beans.
For sure we can choose a different name. I am also not 100% happy with prototype. But we need to be very clear and concise with the wording. Instance
is returned in both cases. A clone
is also not correct, because the factory
of the Component
is invoked every time the Component
is requested.
KOIN uses the terms bean
(singleton) and factory
(no singleton).
What I also found is that some DIF use the term transient
and singleton
(as well as scoped
for session-based contexts, which I also had in mind to implement).
So maybe we choose as of now transient
and singleton
as our scopes (and later on scoped
, if we actually need this). I would also suggest to rename Scope
to Lifetime
. As far as my understanding goes, scope would be more a specific area in an application than the whole lifetime of a component.
Yeah renaming Scope
would be a good idea. I'd be fine with using singleton
and instance
as for my understanding a singleton is a specific instance that only exists once 🤔. transient
would be ok, too but seems a bit more cryptic. Maybe use singleton
and new
/object
?
That is correct in the sense that a singleton
does return the same instance
over and over again. But wouldn't registering a component
as instance
mean the same? Because you are registering an instance of an object, that would imply, that you always get the same instance in return.
Here I also found the terms transient
and singleton
.
The term factory
would also work, because we are not registering the instance of an object but the closure (i.e. factory) of the object, which is for resolving invoked every time the object is requested.
Ah that's tricky, because we are basically only registering factories and neither singletons nor instances but the scope or lifetime is important when it comes to resolving.
So the term factory
would also be displaced.
Settled for the first release even if the choice is maybe not the best the best. We can change that later on.
I stumbled upon the Scope enum and found the
prototype
case a bit misleading: