-
Notifications
You must be signed in to change notification settings - Fork 130
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
Can't define more than one service for a class #232
Comments
can you explain how you try to add the service? each implementation should look like this: use JMS\DiExtraBundle\Annotation as DI;
/**
* @DI\Service("impl1")
*/
class HighBar implements BarInterface
{} use JMS\DiExtraBundle\Annotation as DI;
/**
* @DI\Service("impl2")
*/
class LowBar implements BarInterface
{} |
Yea, that's how'd you'd define different implementations/services for BarInterface. So now let's say I want to define 2 Foo services, one that accepts your HighBar service and another that gets LowBar. This is not too uncommon and I can with Symfony but I don't see a way (yet) to do it with this lib. It expects that the arguments you inject are for the one and only service you can create for the class. Ideally we'd be able to create more than one service for a class. We'd just need a way to specify which service each argument is for. |
ah :) this is still quite easy - http://jmsyst.com/bundles/JMSDiExtraBundle/master/usage#constructor-setter-injection use JMS\DiExtraBundle\Annotation as DI;
class Controller
{
private $impl1;
private $impl2;
/**
* @DI\InjectParams({
* "impl1" = @DI\Inject("impl1"),
* "impl2" = @DI\Inject("impl2")
* })
*/
public function __construct($impl1, $impl2)
{
$this->impl1 = $impl1;
$this->impl2 = $impl2;
}
// ... some actions
} |
I guess we can close this issue? |
You're just injecting two dependencies into one service. I'm saying I don't think you can define more than one service for a class. In Symfony I can do this for example services:
bar_service_high:
class: HighBar
bar_service_low:
class: LowBar
foo_service_one:
class: Foo
arguments: [@bar_service_high]
foo_service_two
class: Foo
arguments: [@bar_service_low] I do not see a way to duplicate that behavior in this lib. |
@johnpancoast I see what you mean, this is actually not supported by this lib and we need to update the Metadata management to support it. |
Cool! I'll try but I'm strapped for time too. I just wanted to make sure I wasn't missing some functionality I wasn't aware of. |
I just tried to implement it, we just need a nice way to inject data for each service :) |
Yup. A way to group them by name would work although i haven't looked at this code yet. I'll open it up today. |
@wodka, awesome. Looks like you're already on this. Let me know if I can help. |
add deprecation warnings add tests fix schmittjoh#232
add deprecation warnings add tests fix schmittjoh#232
add deprecation warnings add tests fix schmittjoh#232
add deprecation warnings add services support to AfterSetup add tests fix schmittjoh#232
Using this bundle how can I define 2 services with different
BarInterface
implementations in this example?The text was updated successfully, but these errors were encountered: