On 10/28/2016 12:34 AM, Hari K T wrote:
You can argue to create wrappers or do in the configuration level. But
for a specification it should be very clear what it returns as Pedro
Cordeiro mentioned in this thread.
Always returns new instance
or
You will always get the same object.
We can of course work on standardizing the notion of "factories"
like described here
(https://github.com/container-interop/container-interop/issues/44
<https://github.com/container-interop/container-interop/issues/44>)
but this is IMHO a whole different PSR as factories may/should not
be containers.
I don't think it need to be a different PSR itself for every
containers have the functionality for the same. Either in
configuration or having a different method. So why not suggest a
method itself ?
I understand that the object creation inside Factory can be using
"new" keyword than using the container itself ie why you suggested a
different PSR. You can create a different PSR for sure.
So in that case as in discussion
https://github.com/container-interop/container-interop/issues/69#issuecomment-251316682
it will be something like
class SomeContainer implements ContainerInterface, FactoryInterface {}
Now your container's get can return new or shared instance depending
on configuration and make / create can create new instances.
Didn't we removed the configuration level of container to return
shared / new instances if we say "get" always return same instance and
"make / create" always create new instance ?
As this discussion started 2 days before and none of the existing FIG
3.0 members have the problem may be this is only concern for me. We
can wrap this up if there is no further issues raised.
I fully agree that the same-instance and new-instance-each-time use
cases exist and are valid. However, I am also not entirely comfortable
with conflating the two.
If I, as a caller (say, in a factory or a dispatcher or one of the few
places where talking to a container is legit) call get(), do I have that
object uniquely or do I share its instance with others? With the spec as
written, I do not know.
In an ideal world, all service objects would be immutable
post-construction so the question would be largely irrelevant. That is
not, however, the case, and many service objects have setters on them
(often for very legitimate reasons, such as a service that is a proxy to
many other services). If I call one of those addSubThingie() methods on
that service, am I modifying a global instance or not? That's very
relevant to my usage of that object. However, I cannot know in the
current spec if it's private or not.
Additionally, non-service objects sometimes end up in the container,
too. No, that's not a great idea but it still happens from time to
time. Are those value objects global or not? Again, very relevant to
my usage of them but not at all clear unless I know how the
implementation I'm using is built, at which point it's no longer
interoperable.
I would prefer to have get() defined to always return the same object
(lazy loaded or otherwise, not relevant here), as that is the typical
case, and another method added (either on the same interface or a
separate one, I am flexible) to handle the factory use case. That way I
know the behavior of each object I get back, specifically in relation to
whether I have a private copy or not.
That is, yes, I would like to see the SHOULD strengthened to a MUST.
--Larry Garfield
--
You received this message because you are subscribed to the Google Groups "PHP
Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/php-fig/41b48295-5814-50d4-3e15-4fdc77fdd0db%40garfieldtech.com.
For more options, visit https://groups.google.com/d/optout.