Entrypoints, Services and Dependencies

Hi. Sorry for the late reply to this.

These questions come up quite a lot. It is fairly common to have a service interface that requires more than one external system, and we ought to have a page in the docs that explains how to do it.

You can do this if you’re happy to couple your two extensions together. Extensions can access every other extension via their ServiceContainer (self.container.extensions is the set of all of them) so you can reach into another extension and do what you like with it.

This is possible but I would not say proper design.

Yes, but not the same way that a service can. You can’t declare DependencyProvider on your Entrypoint, because the dependency injection mechanism only works on service instances.

You can use a nested SharedExtension though, which is more or less the same thing but without the injection part. These are generally used to implement something that needs to be shared between multiple top-level extensions. It is an Extension subclass just like Entrypoint and DependencyProvider, and it has the same lifecycle (i.e. started when the service container starts, runs until the container stops).

Good examples of them in the codebase are the WebServer, shared by all HTTP and websocket entrypoints, and the RpcConsumer, shared by all the RPC entrypoints.

Your plan seems good, except that I would use a SharedExtension instead of a DependencyProvider to implement the next_data() and resubscribe() methods.

Additionally I’d probably use another nested extension to consume from the RabbitMQ resubscription queue. This would avoid polluting your service code with message handling that really belongs to your extension.

Hope that helps, please ask if anything is unclear.

Matt.

1 Like