Github   Telegram
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
components::ComponentContext Class Referencefinal

Class to retrieve other components. More...

#include <userver/components/component_context.hpp>

Public Member Functions

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. More...
 
template<typename T >
T & FindComponent (std::string_view name) const
 
template<typename T >
T * FindComponentOptional () const
 If there's no component with specified type and name return nullptr; otherwise behaves as FindComponent(). More...
 
template<typename T >
T * FindComponentOptional (std::string_view name) const
 
engine::TaskProcessor & GetTaskProcessor (const std::string &name) const
 Returns an engine::TaskProcessor with the specified name.
 
const ManagerGetManager () const
 
bool IsAnyComponentInFatalState () const
 
bool Contains (std::string_view name) const noexcept
 

Friends

class Manager
 

Detailed Description

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).

See also
Components
Examples
components/component_sample_test.cpp, components/component_sample_test.hpp, samples/config_service/config_service.cpp, samples/flatbuf_service/flatbuf_service.cpp, samples/grpc_service/grpc_service.cpp, samples/http_caching/http_caching.cpp, samples/mongo_service/mongo_service.cpp, samples/postgres_service/postgres_service.cpp, samples/redis_service/redis_service.cpp, samples/tcp_full_duplex_service/tcp_full_duplex_service.cpp, and samples/tcp_service/tcp_service.cpp.

Definition at line 64 of file component_context.hpp.

Member Function Documentation

◆ Contains()

bool components::ComponentContext::Contains ( std::string_view  name) const
noexcept
Returns
true if there is a component with the specified name and it could be found via FindComponent()

◆ FindComponent() [1/2]

template<typename T >
T & components::ComponentContext::FindComponent ( ) const
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.

Exceptions
ComponentsLoadCancelledExceptionif components loading was cancelled due to errors in the creation of other component.
std::runtime_errorif component missing in component_list was requested.
Examples
components/component_sample_test.cpp, samples/grpc_service/grpc_service.cpp, and samples/mongo_service/mongo_service.cpp.

Definition at line 78 of file component_context.hpp.

◆ FindComponent() [2/2]

template<typename T >
T & components::ComponentContext::FindComponent ( std::string_view  name) const
inline

Definition at line 84 of file component_context.hpp.

◆ FindComponentOptional() [1/2]

template<typename T >
T * components::ComponentContext::FindComponentOptional ( ) const
inline

If there's no component with specified type and name return nullptr; otherwise behaves as FindComponent().

Definition at line 102 of file component_context.hpp.

◆ FindComponentOptional() [2/2]

template<typename T >
T * components::ComponentContext::FindComponentOptional ( std::string_view  name) const
inline

Definition at line 108 of file component_context.hpp.

◆ IsAnyComponentInFatalState()

bool components::ComponentContext::IsAnyComponentInFatalState ( ) const
Returns
true if one of the components is in fatal state and can not work. A component is in fatal state if the components::ComponentHealth::kFatal value is returned from the overriden components::LoggableComponentBase::GetComponentHealth().

Friends And Related Function Documentation

◆ Manager

friend class Manager
friend

Definition at line 131 of file component_context.hpp.


The documentation for this class was generated from the following file: