Services

Service on the train, van Gogh

Services are interfaces or class instances that are registered locally in a service registry and can be fetched and used by the system or plugins.

The service registry is the most important class in a nyssr.net node. This is due to one of the core points of our philosophy: code hiding. A large number of internal services are published via the service registry. In most cases these are interfaces, the respective implementations remain private.

The question naturally arises why we didn't implement a pattern like Dependency Injection, like other popular frameworks. This is partly due to the original origin of our system (OSGi), and partly because of the asynchronous nature of the framework. In addition, much of the code is based on plugins, which are loaded at runtime. With the service registry approach, we have chosen a pattern that is easy to understand, that does not present any puzzles and simply does what it is supposed to do. The price for this is some extra code we have to write for the service starters (see below).

A service in nyssr.net is not simply started by itself. It is indicated to the system as startable. This is done by registering classes that implement the IServiceStarter interface. Service starters provide a list of dependencies of the service to be started. If all dependencies can be fulfilled, that is, if all required services have already been started, then this service will be started as well. To start the service, the service starter implements a start method. In this method, the own service can be started and registered to the service registry. When a service is dropped, all services that depend on that service are stopped by a stop method.