#include <userver/components/component_context.hpp>
Class to retrieve other components.
Only the const member functions of this class are meant for usage in component constructor (because of that this class is always passed as a const reference to the constructors).
For usage outside the component constructor see components::State.
Definition at line 79 of file component_context.hpp.
Public Member Functions | |
| ComponentContext (ComponentContext &&)=delete | |
| ComponentContext & | operator= (ComponentContext &&)=delete |
| template<typename T> | |
| T & | FindComponent () const |
| Finds a component of type T with specified name (if any) and returns the component after it was initialized. | |
| template<typename T> | |
| T & | FindComponent (std::string_view name) const |
| template<typename T> | |
| T & | FindComponent (std::string_view={}) |
| template<typename T> | |
| T * | FindComponentOptional () const |
| If there's no component with specified type and name return nullptr; otherwise behaves as FindComponent(). | |
| template<typename T> | |
| T * | FindComponentOptional (std::string_view name) const |
| template<typename T> | |
| T & | FindComponentOptional (std::string_view={}) |
| engine::TaskProcessor & | GetTaskProcessor (std::string_view name) const |
| Returns an engine::TaskProcessor with the specified name. | |
| template<typename T> | |
| engine::TaskProcessor & | GetTaskProcessor (const T &) |
| std::string_view | GetComponentName () const |
| Returns the current component name. This is helpful in cases where multiple instances of the component class may be created using component_list.Append<T>("custom-name") syntax. | |
| utils::ResourceScopeStorage & | Scopes () const |
| Returns utils::ResourceScopeStorage that can be used (by a component or any other class) to register user resources. | |
|
inline |
Finds a component of type T with specified name (if any) and returns the component after it was initialized.
Can only be called from other component's constructor in a task where that constructor was called. May block and asynchronously wait for the creation of the requested component.
| ComponentsLoadCancelledException | if components loading was cancelled due to errors in the creation of other component. |
| std::runtime_error | if component missing in component_list was requested. |
Definition at line 96 of file component_context.hpp.
|
inline |
Definition at line 102 of file component_context.hpp.
|
inline |
Definition at line 117 of file component_context.hpp.
|
inline |
If there's no component with specified type and name return nullptr; otherwise behaves as FindComponent().
Definition at line 124 of file component_context.hpp.
|
inline |
Definition at line 130 of file component_context.hpp.
|
inline |
Definition at line 138 of file component_context.hpp.
| std::string_view components::ComponentContext::GetComponentName | ( | ) | const |
Returns the current component name. This is helpful in cases where multiple instances of the component class may be created using component_list.Append<T>("custom-name") syntax.
|
inline |
Definition at line 146 of file component_context.hpp.