// Copyright (c) 2004-present, Facebook, Inc. // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. #pragma once #include #include #include #include #include namespace facebook { namespace react { class ContextContainer; using SharedContextContainer = std::shared_ptr; /* * General purpose dependecy injection container. */ class ContextContainer final { public: template void registerInstance(std::shared_ptr instance) { std::lock_guard lock(mutex_); instances_.insert({std::type_index(typeid(T)), instance}); } template std::shared_ptr getInstance() const { std::lock_guard lock(mutex_); return std::static_pointer_cast(instances_.at(std::type_index(typeid(T)))); } private: std::unordered_map> instances_; mutable std::mutex mutex_; }; } // namespace react } // namespace facebook