A pattern that I've been using for many years now is that of "singleton environments". I will illustrate the concept with some code, but the code hasn't been compiled (thus, might have typos).
The idea is that you might want to run more than one server, and more than one client, in a testing environment, but you want them all to run within the same process for easy debugging. This comes up especially when developing networked games.
You can't just make everything a traditional singleton at that point, because the different executing instances (say, two zone servers and two client windows) would step on each other.
Instead, the concept of an execution environment as a singleton factory can be used. For each service that you want to be able to expose to parts of your program (server, client, or both), set up a factory which knows how to create an instance of that service, and then vector through a map from service type to instance, and have the map create the service on first access.
In addition, you can make environments that are decorators on other environments, returning their own instances where no instance is present in the base environment.
This way, you create one execution environment per logical program instance you want to run, and configure your program objects with this environment. The program will use this environment, and all services created out of that environment will, in turn, use the environment for their needed services. This keeps everything compartmentalized, letting you run multiple instances of "applications" within the single process.
For some services, like file system and event scheduling, you might want to use the same instance for all the program instances; you can accomplish this by configuring the environment up-front with these instances.
The pattern in usage looks a bit like:
Let's assume that LoginServer needs an IEventScheduler, an INetwork and an IDatabase. Its constructor would look something like:
Similarly, the ZoneServer and Client instances would get the services they need out of their respective environments. The service instances (except for the manually created services) get automatically created on demand, and initialized with the environment that the instance belongs to. Thus, an IDatabase service might actually want to use an INetwork and an IFileSystem internally, and get that from the environment.
To implement a service, you'd implement its interface, and have a constructor that can be called by the environment.
This code assumes that the interface for IDatabase is an abstract base class that lives in some header, and DatabaseImpl actually implements that interface as a service, and the class declaration for DatabaseImpl actually lives in a cpp file (not a header file) because only the service factory needs the concrete class. This pattern will be used throughout the rest of the code: concrete classes go in source files; abstract classes, and templates go in headers.
So, the implementation of IEnvironment and of ServiceFactory is left. I think you can actually figure those out for yourselves, but I'll sketch them out:
Note that the cast through void* looks scary, but the fact that the execution environment, in turn, also uses templates makes it type safe (enough).
The service factories get registered during static program initialization, before main() is executed, so you cannot use an environment until you get to main(). Typically, that's a pretty good rule to use anyway: doing too much work before main() leads to very hard to maintain and debug code.
So, there you have it. It's really quite a powerful way of managing what environment each piece of code executes within, without having to resort to process-global singleton instances. The minor overhead of looking up a service can usually just be paid for when you don't need to do it all that often, and if you do it often enough to matter, you will get the value into a local member variable, which is more efficient than the global-singleton pattern anyway (because it's branch-less and function-call-less).