plugify 1.2.8
|
DI Container / Service Locator with PIMPL. More...
#include <service_locator.hpp>
Classes | |
class | ServiceBuilder |
Public Member Functions | |
ServiceLocator (const ServiceLocator &)=delete | |
ServiceLocator & | operator= (const ServiceLocator &)=delete |
ServiceLocator (ServiceLocator &&) noexcept | |
ServiceLocator & | operator= (ServiceLocator &&) noexcept |
template<typename Interface , typename Implementation = Interface> requires (std::is_base_of_v<Interface, Implementation>) | |
void | RegisterInstance (std::shared_ptr< Implementation > instance) |
Register a concrete instance (singleton) | |
template<typename Interface > | |
void | RegisterFactory (std::function< std::shared_ptr< Interface >()> factory, ServiceLifetime lifetime=ServiceLifetime::Transient) |
Register a factory function. | |
template<typename Interface , typename Implementation = Interface> requires (std::is_base_of_v<Interface, Implementation> && std::is_default_constructible_v<Implementation>) | |
void | RegisterType (ServiceLifetime lifetime=ServiceLifetime::Transient) |
Register a type with automatic construction. | |
template<typename Interface , typename Implementation , typename... Dependencies> requires (std::is_base_of_v<Interface, Implementation>) | |
void | RegisterWithDependencies (std::function< std::shared_ptr< Implementation >(Dependencies...)> constructor, ServiceLifetime lifetime=ServiceLifetime::Transient) |
Register with dependency injection. | |
template<typename Interface , typename Implementation = Interface> requires (std::is_base_of_v<Interface, Implementation>) | |
void | RegisterInstanceIfMissing (std::shared_ptr< Implementation > instance) |
Register a concrete instance if missing (singleton) | |
template<typename Interface > | |
void | RegisterFactoryIfMissing (std::function< std::shared_ptr< Interface >()> factory, ServiceLifetime lifetime=ServiceLifetime::Transient) |
Register a factory function. | |
template<typename Interface , typename Implementation = Interface> requires (std::is_base_of_v<Interface, Implementation> && std::is_default_constructible_v<Implementation>) | |
void | RegisterTypeIfMissing (ServiceLifetime lifetime=ServiceLifetime::Transient) |
Register a type with automatic construction. | |
template<typename Interface , typename Implementation , typename... Dependencies> requires (std::is_base_of_v<Interface, Implementation>) | |
void | RegisterWithDependenciesIfMissing (std::function< std::shared_ptr< Implementation >(Dependencies...)> constructor, ServiceLifetime lifetime=ServiceLifetime::Transient) |
Register with dependency injection. | |
template<typename Interface > | |
std::shared_ptr< Interface > | Resolve () const |
Resolve a service. | |
template<typename Interface > | |
std::shared_ptr< Interface > | TryResolve () const noexcept |
Try to resolve a service (returns nullptr if not found) | |
template<typename Interface > | |
bool | IsRegistered () const |
Check if a service is registered. | |
void | BeginScope () |
Create a new scope (for scoped services) | |
void | EndScope () |
End current scope. | |
void | Clear () |
Clear all registrations. | |
size_t | Count () const |
Get the number of registered services. | |
ServiceBuilder | Services () |
DI Container / Service Locator with PIMPL.
Definition at line 20 of file service_locator.hpp.
|
inline |
Check if a service is registered.
Definition at line 179 of file service_locator.hpp.
|
inline |
Register a factory function.
Definition at line 51 of file service_locator.hpp.
|
inline |
Register a factory function.
Definition at line 107 of file service_locator.hpp.
|
inline |
Register a concrete instance (singleton)
Definition at line 41 of file service_locator.hpp.
|
inline |
Register a concrete instance if missing (singleton)
Definition at line 94 of file service_locator.hpp.
|
inline |
Register a type with automatic construction.
Definition at line 66 of file service_locator.hpp.
|
inline |
Register a type with automatic construction.
Definition at line 125 of file service_locator.hpp.
|
inline |
Register with dependency injection.
Definition at line 76 of file service_locator.hpp.
|
inline |
Register with dependency injection.
Definition at line 138 of file service_locator.hpp.
|
inline |
Resolve a service.
Definition at line 160 of file service_locator.hpp.
|
inlinenoexcept |
Try to resolve a service (returns nullptr if not found)
Definition at line 170 of file service_locator.hpp.