Karl von Randow Staring a bit longer into the spec, there is the following statement about the collection of alternatives you are getting:
getAlternatives() returns the ordered list of enabled alternatives for the application, sorted by priority in ascending order. Alternatives enabled for a bean archive are not included in the list.
This ultimately means that the highest priority that exists in the list is the rightmost element. Hence anything you add as a next element into the list will become rightmost and will have the priority of the previously highest value plus some constant (in this case it should be +10). So this new element inevitably becomes the one with the highest priority in the whole list. So taking what you said:
If prior to AfterTypeDiscovery the alternatives list already contains an alternative implementation of FooService with a priority (say 100), but it's not the last item in the alternatives list, then an Extension adds another alternative of FooService, that new alternative will get a priority 10 greater than the priority of the last alternative in the list, but not necessarily greater than 100, and therefore will not be chosen.
In this case, if there is FooService with 100 and it is not last item in the list, then any last item has to have more then 100 priority and anything you add behind that will have even more than that and certainly more then 100. With this in mind, I am failing to see the issue you are having, could you maybe provide a reproducer or a more in depth description of what you are seeing? |