#pragma once #include "common/singleton/threadsafe_singleton.h" namespace Envoy { // Note this class is not thread-safe, and should be called exceedingly carefully. template class TestThreadsafeSingletonInjector { public: TestThreadsafeSingletonInjector(T* instance) { latched_instance_ = &ThreadSafeSingleton::get(); ThreadSafeSingleton::instance_ = instance; } ~TestThreadsafeSingletonInjector() { ThreadSafeSingleton::instance_ = latched_instance_; } T& latched() { return *latched_instance_; } private: T* latched_instance_; }; } // namespace Envoy