You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Denis Stepanov <de...@gmail.com> on 2012/03/22 13:55:08 UTC

Tapestry IOC @Primary

Would be possible to change the default behaviour to select a service marked @Primary when there are multiple occurrences of the same interface? I'm finding that it's complicated to add a service with the same interface, I need to find all occurrences of the interface and mark them @Primary and it isn't possible when there is a third-party library relying on it. I would like have the same interface for the @Local and the @Clustered service and I would like to keep the local to be the primary without changing the interface or marking access points.

Denis



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Re: Tapestry IOC @Primary

Posted by Denis Stepanov <de...@gmail.com>.
I understand, but there are situations when you just can't change the code containing the point of injection. If you know that there will be more than one service of the specific interface, using a marker annotation is a way to go, but when you don't know it and you decide to add a service in the future there could be a problem.

Simple example would be extending the functionality of the service by creating a new one and mostly delegating to the original one, lets say I want to change the service to be async, but I also want to allow to inject the previous sync service.

My suggestion is to make the @Primary annotation the special one, service implementation marked with the @Primary will be selected without labeling the point of injection.

The whole idea is to provide backwards compatibility, but also allowing to get rid of the @Primary so developers, who didn't write the code, don't need to know about its implementation in a case of the chain or the strategy pattern.

Denis


Mar 24, 2012 v 1:11 AM, Howard Lewis Ship:

> But you can label the point of injection with @Primary, that's the
> whole point of using marker annotations for disambiguation.
> 
> On Thu, Mar 22, 2012 at 10:55 AM, Denis Stepanov
> <de...@gmail.com> wrote:
>> You didn't understand me, I have only one implementation with the @Primary, the problem is when you are accesing the service without it.
>> 
>> Example:
>> 
>> MyService.class, new Clustered();
>> MyService.class, new Local(); @Primary
>> 
>> 
>> @Inject
>> MyService service <-- this will fail because there are two implementations, adding @Primary will help
>> 
>> My suggestion is to change the default behaviour to select a service with the @Primary when there are more than one implementations of the same interface.
>> 
>> Denis
>> 
>> 
>> Mar 22, 2012 v 6:17 PM, Igor Drobiazko:
>> 
>>> The @Primary annotation is supposed to be placed on a single
>>> implementation, not all of them. The most frequent use case is a service
>>> which is implemented as a chain or a strategy.
>>> 
>>> On Thu, Mar 22, 2012 at 1:55 PM, Denis Stepanov <de...@gmail.com>wrote:
>>> 
>>>> Would be possible to change the default behaviour to select a service
>>>> marked @Primary when there are multiple occurrences of the same interface?
>>>> I'm finding that it's complicated to add a service with the same interface,
>>>> I need to find all occurrences of the interface and mark them @Primary and
>>>> it isn't possible when there is a third-party library relying on it.
>>> 
>>> I would like have the same interface for the @Local and the @Clustered
>>>> service and I would like to keep the local to be the primary without
>>>> changing the interface or marking access points.
>>>> 
>>>> Denis
>>>> 
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
>>>> For additional commands, e-mail: dev-help@tapestry.apache.org
>>>> 
>>>> 
>>> 
>>> 
>>> --
>>> Best regards,
>>> 
>>> Igor Drobiazko
>>> http://tapestry5.de
>>> http://twitter.com/drobiazko
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: dev-help@tapestry.apache.org
>> 
> 
> 
> 
> -- 
> Howard M. Lewis Ship
> 
> Creator of Apache Tapestry
> 
> The source for Tapestry training, mentoring and support. Contact me to
> learn how I can get you up and productive in Tapestry fast!
> 
> (971) 678-5210
> http://howardlewisship.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: dev-help@tapestry.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Re: Tapestry IOC @Primary

Posted by Howard Lewis Ship <hl...@gmail.com>.
But you can label the point of injection with @Primary, that's the
whole point of using marker annotations for disambiguation.

On Thu, Mar 22, 2012 at 10:55 AM, Denis Stepanov
<de...@gmail.com> wrote:
> You didn't understand me, I have only one implementation with the @Primary, the problem is when you are accesing the service without it.
>
> Example:
>
> MyService.class, new Clustered();
> MyService.class, new Local(); @Primary
>
>
> @Inject
> MyService service <-- this will fail because there are two implementations, adding @Primary will help
>
> My suggestion is to change the default behaviour to select a service with the @Primary when there are more than one implementations of the same interface.
>
> Denis
>
>
> Mar 22, 2012 v 6:17 PM, Igor Drobiazko:
>
>> The @Primary annotation is supposed to be placed on a single
>> implementation, not all of them. The most frequent use case is a service
>> which is implemented as a chain or a strategy.
>>
>> On Thu, Mar 22, 2012 at 1:55 PM, Denis Stepanov <de...@gmail.com>wrote:
>>
>>> Would be possible to change the default behaviour to select a service
>>> marked @Primary when there are multiple occurrences of the same interface?
>>> I'm finding that it's complicated to add a service with the same interface,
>>> I need to find all occurrences of the interface and mark them @Primary and
>>> it isn't possible when there is a third-party library relying on it.
>>
>> I would like have the same interface for the @Local and the @Clustered
>>> service and I would like to keep the local to be the primary without
>>> changing the interface or marking access points.
>>>
>>> Denis
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: dev-help@tapestry.apache.org
>>>
>>>
>>
>>
>> --
>> Best regards,
>>
>> Igor Drobiazko
>> http://tapestry5.de
>> http://twitter.com/drobiazko
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: dev-help@tapestry.apache.org
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Re: Tapestry IOC @Primary

Posted by Denis Stepanov <de...@gmail.com>.
You didn't understand me, I have only one implementation with the @Primary, the problem is when you are accesing the service without it.

Example:

MyService.class, new Clustered();
MyService.class, new Local(); @Primary


@Inject
MyService service <-- this will fail because there are two implementations, adding @Primary will help

My suggestion is to change the default behaviour to select a service with the @Primary when there are more than one implementations of the same interface. 

Denis
 

Mar 22, 2012 v 6:17 PM, Igor Drobiazko:

> The @Primary annotation is supposed to be placed on a single
> implementation, not all of them. The most frequent use case is a service
> which is implemented as a chain or a strategy.
> 
> On Thu, Mar 22, 2012 at 1:55 PM, Denis Stepanov <de...@gmail.com>wrote:
> 
>> Would be possible to change the default behaviour to select a service
>> marked @Primary when there are multiple occurrences of the same interface?
>> I'm finding that it's complicated to add a service with the same interface,
>> I need to find all occurrences of the interface and mark them @Primary and
>> it isn't possible when there is a third-party library relying on it.
> 
> I would like have the same interface for the @Local and the @Clustered
>> service and I would like to keep the local to be the primary without
>> changing the interface or marking access points.
>> 
>> Denis
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: dev-help@tapestry.apache.org
>> 
>> 
> 
> 
> -- 
> Best regards,
> 
> Igor Drobiazko
> http://tapestry5.de
> http://twitter.com/drobiazko


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Re: Tapestry IOC @Primary

Posted by Igor Drobiazko <ig...@gmail.com>.
The @Primary annotation is supposed to be placed on a single
implementation, not all of them. The most frequent use case is a service
which is implemented as a chain or a strategy.

On Thu, Mar 22, 2012 at 1:55 PM, Denis Stepanov <de...@gmail.com>wrote:

> Would be possible to change the default behaviour to select a service
> marked @Primary when there are multiple occurrences of the same interface?
> I'm finding that it's complicated to add a service with the same interface,
> I need to find all occurrences of the interface and mark them @Primary and
> it isn't possible when there is a third-party library relying on it.

I would like have the same interface for the @Local and the @Clustered
> service and I would like to keep the local to be the primary without
> changing the interface or marking access points.
>
> Denis
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: dev-help@tapestry.apache.org
>
>


-- 
Best regards,

Igor Drobiazko
http://tapestry5.de
http://twitter.com/drobiazko