Global objects complicate testing and prevent the use of dependency injection. The refactor properly assigns ownership of the shared state of the server to the Server object and firmly couples the NativeClient to the server as well.
Implementation
The shared state of the server is mainly two things: the list of active endpoints and the model repository. These are now owned by the Server object and passed to the HTTP and gRPC servers when those are started. Since the NativeClient directly accesses these methods, it now requires a pointer to the running server and it will get its internal state from there. This way, users are also prevented from creating a NativeClient to communicate with a server they don't have access to.
Notes
There are a few global objects remaining still:
Logger - spdlog is global by nature. Could get loggers once and pass them around
Metrics - still a global singleton
GrpcServer - a singleton created by start()
HttpServer - Drogon is internally using globals that make destroying it difficult (#1377)
Summary of Changes
RequestParameters
toParameterMap
Motivation
Global objects complicate testing and prevent the use of dependency injection. The refactor properly assigns ownership of the shared state of the server to the Server object and firmly couples the NativeClient to the server as well.
Implementation
The shared state of the server is mainly two things: the list of active endpoints and the model repository. These are now owned by the Server object and passed to the HTTP and gRPC servers when those are started. Since the NativeClient directly accesses these methods, it now requires a pointer to the running server and it will get its internal state from there. This way, users are also prevented from creating a NativeClient to communicate with a server they don't have access to.
Notes
There are a few global objects remaining still: