IServiceInstance¶
-
struct IServiceInstance¶
Subclassed by sb::di::details::AliasService, sb::di::details::ExternalService< T >, sb::di::details::InPlaceService< T >, sb::di::details::UniquePtrService< T >
Public Types
-
using Ptr = std::unique_ptr<IServiceInstance>¶
-
using SPtr = std::shared_ptr<IServiceInstance>¶
Public Functions
-
virtual void *get() const = 0¶
Returns service pointer as void *.
-
virtual void *getForMoveOut() = 0¶
Returns service pointer as void *,.
Method is used to ensure that service can be moved out
- Throws:
sb::di::CannotMoveOutServiceException – Example:
void* service = instance->getForMoveOut();
-
virtual void *release() = 0¶
Releases service ownership as void *.
If instance is owner of service it will release this ownership just like std::unique_ptr<T>::release(), otherwise it will throw exception
Example:
std::unique_ptr<T> service{static_cast<T *>(instance->release())};
Warning
Using this method might cause memory leaks, client is responsible for managing this pointner lifetime, the best approach is to immediately wrap this pointer with proper std::unique_ptr<T>
- Throws:
sb::di::CannotReleaseServiceException –
-
virtual TypeId getTypeId() const = 0¶
Get the TypeId of service.
This method can be used to check if casting is safe
Example:
if(instance->getTypeId() == typeid(T)) { T* service = instance->getAs<T>(); }
-
virtual bool isValid() const = 0¶
Checks if service instance is valid.
If service instance is invalid, get and release methods might lead to undefined behaviour
-
virtual ~IServiceInstance() = default¶
-
using Ptr = std::unique_ptr<IServiceInstance>¶