Skip to content

[2.0] changed services to be shared by default#83

Merged
fabpot merged 1 commit intomasterfrom
prototype-share
Nov 11, 2013
Merged

[2.0] changed services to be shared by default#83
fabpot merged 1 commit intomasterfrom
prototype-share

Conversation

@fabpot
Copy link
Copy Markdown
Member

@fabpot fabpot commented Nov 10, 2013

Now that we have several years of experience using Pimple, I think everyone agrees that having to call share everytime you need to define a service is cumbersome. And it is even error-prone when calling extend as one needs to call share again.
#62 proposes a shortcut for the extend use case, but I want to go one step further in Pimple 2.0: remove the need to call share altogether.

The reasoning is quite simple: services are 99.9% shared (I don't even have an example for a prototype service).

So, this PR makes closure shared by default. If you need to define a prototype service, call prototype.

This change is almost backward compatible as the share method is kept as a no-op method. The only BC break is if you have a prototype service in which case you need to wrap it with a prototype call.

Of course, Pimple 2.0 will be used in Silex 2.0, which will make things much easier to read and shorter.

TODO:

  • update docs and website for 2.0

@igorw
Copy link
Copy Markdown
Contributor

igorw commented Nov 10, 2013

👍

@MAXakaWIZARD
Copy link
Copy Markdown

good idea!

@Crell
Copy link
Copy Markdown

Crell commented Nov 10, 2013

Seems eminently sensible. +1

@stof
Copy link
Copy Markdown
Contributor

stof commented Nov 10, 2013

👍

@GromNaN
Copy link
Copy Markdown
Contributor

GromNaN commented Nov 10, 2013

👍 The README should be updated accordingly.

@davedevelopment
Copy link
Copy Markdown
Contributor

👍

@lyrixx
Copy link
Copy Markdown
Contributor

lyrixx commented Nov 11, 2013

good idea.

fabpot added a commit that referenced this pull request Nov 11, 2013
This PR was merged into the master branch.

Discussion
----------

[2.0] changed services to be shared by default

Now that we have several years of experience using Pimple, I think everyone agrees that having to call `share` everytime you need to define a service is cumbersome. And it is even error-prone when calling `extend` as one needs to call `share` again.

#62 proposes a shortcut for the extend use case, but I want to go one step further in Pimple 2.0: remove the need to call `share` altogether.

The reasoning is quite simple: services are 99.9% shared (I don't even have an example for a prototype service).

So, this PR makes closure shared by default. If you need to define a prototype service, call `prototype`.

This change is almost backward compatible as the `share` method is kept as a no-op method. The only BC break is if you have a prototype service in which case you need to wrap it with a `prototype` call.

Of course, Pimple 2.0 will be used in Silex 2.0, which will make things much easier to read and shorter.

TODO:

 - [x] update docs and website for 2.0

Commits
-------

e5309ac changed services to be shared by default
@fabpot fabpot merged commit e5309ac into master Nov 11, 2013
@stof
Copy link
Copy Markdown
Contributor

stof commented Nov 11, 2013

@fabpot I just thought of an extra improvement to avoid mistakes: is it possible that extending a prototype service would automatically mark it as a prototype too ? currently, it requires wrapping it again in a prototype() call. I don't see any reason to change the scope of the service when extending it.

@stof
Copy link
Copy Markdown
Contributor

stof commented Nov 11, 2013

and you should tag a 1.x release just before this merge IMO

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add a @deprecated note?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

9 participants