-
-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
autowiring via Service[] (WIP) #178
Conversation
So simple. 👍 |
4700fe0
to
a2cec9c
Compare
73cff52
to
9144555
Compare
This is definetly time saver! |
Without this (and previous class MyCollection
{
public function add(MyInterface $service) {...}
} and this DI extension which, in a short, finds all services of With proposed syntax, I don't need the extension anymore, because this collections have static factory |
I'm solving it with this package which is much more powerful. This only solves the most simple use-case so it's not nearly enough for me. |
@enumag Can you describe what it does? |
@dg Sure. Basically when dealing with multiple services of the same type there are two use-cases:
When integrating symfony/form to nette I also needed a third case which is in fact a combination of the first two - a resolver that returns an iterator of services. This was necessary for FormTypeExtensions - each FormType in symfony can have multiple FormTypeExtensions. I realize it's not really too related to this PR, I just want to point out the fact that you rarely need all the services of the same type. The second use-case is much more common from my experience. You might want to consider addressing it too in the future. |
1fc7645
to
485a875
Compare
Point 2 looks useful, it is good idea to have multiple form of accessor. interface DbAccessor
{
function get(): Db;
// and allow this too:
function get($name): Db
} There should be enumeration of services in configuration, ie.: services:
- DbAccessor(
name1: @a
name2: @b
)
a: Db('***')
b: Db('***')
c: Db('***') |
Personally I prefer configuration with tags (the name is a tag attribute) instead of inventing some new syntax but that's a detail. Which service would the |
Currently there si supported this syntax services:
- DbAccessor(@a) so it is only enhancement. Tags seems like another good way. |
Oh, right, forgot about that. Yeah this seems like a good improvement. 👍 |
9144555
to
a96c6b4
Compare
a96c6b4
to
36162f3
Compare
36162f3
to
d1c0598
Compare
a27a10b
to
594a33a
Compare
I tried to implement this feature in Symfony, where it's hard to get into config yaml parsing or hack into autowiring. https://github.com/rectorphp/rector/pull/660/files#diff-6303621e84b7d6786a9fd24b8c2be71d Let's see how it works in practice :) thanks for inspiration |
d1c0598
to
0a386c0
Compare
5f1f854
to
286f0d8
Compare
af4a148
to
e64586a
Compare
e64586a
to
4341047
Compare
4341047
to
855b4a7
Compare
855b4a7
to
db22513
Compare
db22513
to
d70d7fd
Compare
d70d7fd
to
0f952f2
Compare
a21dfbd
to
66353fe
Compare
0f952f2
to
ff55601
Compare
ff55601
to
9a49252
Compare
Autowiring of array of
Service
this way: (BC break)