There are a few issues with ServiceContext and its usage in general. Namely:
- It insists on owning the corresponding Service instance, but there have been many practical instances where this is undesirable and we want to control lifetime through other means.
- We do this goofy thing where a Service can assume it has a context(), but the context() is injected externally once OnStart() is received. This feels like an anti-pattern (having an almost-pure virtual interface that also has some data injected into it) and has been a source of confusion. It's also unnecessary.
- ServiceContext working as it does also forces ServiceRunner to take ownership of the Service its running, which has no practical value but again imposes awkward constraints on developers
- ServiceContext also forces us to lean on ForwardingService in cases where we do need better lifecycle control, and this is gross.
We should introduce a ServiceBinding which does the same essential work as ServiceContext -- communicates with the Service Manager and hides boilerplate details from service implementations -- without the awkward ownership requirement.
Comment 1 by roc...@chromium.org
, Oct 3