Your opinion will help to improve our service
Leave a feedback >#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).
ComponentContext
in your component! Lifetime of the passed ComponentContext
ends as soon as the constructor ends.For usage outside the component constructor see components::State.
Definition at line 75 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. | |
|
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 92 of file component_context.hpp.
|
inline |
Definition at line 98 of file component_context.hpp.
|
inline |
Definition at line 113 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 120 of file component_context.hpp.
|
inline |
Definition at line 126 of file component_context.hpp.
|
inline |
Definition at line 134 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.
std::string
if needed.
|
inline |
Definition at line 142 of file component_context.hpp.