Hi,
Am 01.09.2015 um 19:40 schrieb Thiago H. de Paula Figueiredo:
Sometimes you have a service defined by an interface and you want another
service which is
defined by a subinterface.
In those cases you can use @Service to select the correct implementation.
Then you need to track every single injection of that service, and that's
when you can change the source, which isn't always the case.
I haven't thought of the case where you cannot change the source of the
class where the service is *injected*. That could be a problem indeed.
You can work with ServiceOverrides but only if only one of the
implementations is already a service.
I don't think adding this is risky exactly because you need to be
deliberate, marking the default service instance with @Primary or, better
yet, a completely new annotation.
Yes, a new annotation is probably a good idea. @Default?
But this will only help if you can change the source of the module where
the service is *created*. ;-) But if you pull in multiple modules that
bind the same interface with different implementations and without a
service id or marker, you're probably going to have a problem anyway.
I wonder if there's a solution that can address all the possible cases,
and even those where you can change neither the service building nor the
injections. I'm thinking of something like
interface InjectionCandidate<T> {
public Collection<Annotation> getMarkers();
public T getValue();
}
interface InjectionCandidateSelector {
public <T> T selectCandidate(Collection<InjectionCandidate<T>>
candidates);
}
The default implementation would just fail if there is not exactly one
candidate, but you could override it with something like
if (candidates.size() > 1) {
return candidates.stream()
.filter((final InjectionCandidate candidate) ->
candidate.getMarkers().contains(Primary.class)).findFirst()
.orElseThrow(RuntimeException::new).getValue();
}
Jochen
On Tue, 25 Aug 2015 10:15:45 -0300, Nathan Quirynen (JIRA)
<[email protected]> wrote:
Nathan Quirynen created TAP5-2491:
-------------------------------------
Summary: Default marker annotation
Key: TAP5-2491
URL: https://issues.apache.org/jira/browse/TAP5-2491
Project: Tapestry 5
Issue Type: Improvement
Components: tapestry-core
Affects Versions: 5.3.7
Reporter: Nathan Quirynen
Priority: Minor
It would be nice when making use of Marker annotations for tagging a
service, that a default marker value could be defined. So when no
marker annotation is added to the injection of the service this
defined default will be used.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]