Daemon Services
In SanteDB, a daemon service represents a service which is activated on startup and is shut down on service stop. Daemon services can exist on the iCDR and dCDR interfaces. Daemon services are implemented using the IDaemonService
Daemons are particularly useful when:
The plugin needs to subscribe to events on other services
The plugin needs to register / configure other services on application start
The plugin wants a long-running background task (like a messaging interface, listener, etc.)
Lifecycle
Daemons go through the same lifecycle as the primary application host. Daemons have their .Start()
method called at Stage 2 of the application startup and their .Stop()
method called when the application host is shutting down.
Implementation
Daemon Scaffolding
Implementing the IDaemonService interface is all that is required to indicate a particular implementation is a daemon.
Events
The IDaemonService implementation has four events which daemons are expected to raise. These events allow other modules/services to detect when your daemon has completed the necessary steps to start its services. For example, you may wish to have your daemon only start after a repository service is finished starting up, etc. The events are:
Current Status
You should allow other services to detect whether your daemon has completed startup and is currently active. This state is indicated by the IsRunning
property.
Start/Stop Methods
The Start()
method should, at minimum be implemented as:
The Stop() method is implemented in a similar manner:
Last updated