Skip to content
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

No complaint while obtaining a service from multiple services involves ambiguity #407

Open
kitchoi opened this issue May 6, 2021 · 2 comments

Comments

@kitchoi
Copy link
Contributor

kitchoi commented May 6, 2021

    contributed_service_offers = List(contributes_to=envisage_ids.SERVICE_OFFERS)

    def _contributed_service_offers_default(self):
        service_offer1 = ServiceOffer(
            protocol=SomeClass, factory=factory1
        )
        service_offer2 = ServiceOffer(
            protocol=SomeClass, factory=factory2
        )
        return [service_offer1, service_offer2]

If a plugin, or two plugins in conjunction, contributes two service offers that have the same protocol but different factory, then I'd expect this to be at least a warning, or possibly an error, to the maintainer of a plugin manager. This is because it is ambiguous which of factory1 or factory2 would have been used when one obtains a service via application.get_service(SomeClass), so this likely indicates programming errors or oversights.

Currently no such warnings or errors would occur.

(Sorry for a somewhat curt description as I did not want this observation to go unreported.)

@kitchoi
Copy link
Contributor Author

kitchoi commented May 10, 2021

@mdickinson For awareness, this issue is tangentially related to the awkwardness with having to subclass (say the SomeClass here) just to offer two services of the same type but used for different purposes.

@kitchoi
Copy link
Contributor Author

kitchoi commented May 12, 2021

At the very least, a warning in here would be good:

if len(services) > 0:
service = services[0]

@kitchoi kitchoi changed the title No complaint if two distinct ServiceOffer for the same protocol are contributed No complaint while obtaining a service from multiple services involves ambiguity May 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant