|
solinject
1.0.0
C++17 Dependency Injection header-only library
|
Go to the source code of this file.
Macros | |
| #define | FROM_DI(class_) (c.template GetRequiredService<class_>()) |
| Injects a required service from a DI container. More... | |
| #define | FROM_DI_OPTIONAL(class_) (c.template GetService<class_>()) |
| Injects an optional service from a DI container. More... | |
| #define | FROM_DI_MULTIPLE(class_) (c.template GetServices<class_>()) |
| Injects multiple instances of a service from a DI container. More... | |
| #define | FACTORY(class_, ...) |
| Service factory. More... | |
| #define | RegisterSingletonService(container, class_, ...) (container).template RegisterSingletonService<class_>(FACTORY(class_, __VA_ARGS__)) |
| Registers a service with singleton lifetime. More... | |
| #define | RegisterSingletonInterface(container, interface_, implementation, ...) (container).template RegisterSingletonService<interface_>(FACTORY(implementation, __VA_ARGS__)) |
| Registers a service with singleton lifetime as an implementation of a specific interface. More... | |
| #define | RegisterTransientService(container, class_, ...) (container).template RegisterTransientService<class_>(FACTORY(class_, __VA_ARGS__)) |
| Registers a service with transient lifetime. More... | |
| #define | RegisterTransientInterface(container, interface_, implementation, ...) (container).template RegisterTransientService<interface_>(FACTORY(implementation, __VA_ARGS__)) |
| Registers a service with transient lifetime as an implementation of a specific interface. More... | |
| #define | RegisterSharedService(container, class_, ...) (container).template RegisterSharedService<class_>(FACTORY(class_, __VA_ARGS__)) |
| Registers a service with shared lifetime. More... | |
| #define | RegisterSharedInterface(container, interface_, implementation, ...) (container).template RegisterSharedService<interface_>(FACTORY(implementation, __VA_ARGS__)) |
| Registers a service with shared lifetime as an implementation of a specific interface. More... | |
| #define | RegisterScopedService(container, class_, ...) (container).template RegisterScopedService<class_>(FACTORY(class_, __VA_ARGS__)) |
| Registers a service with scoped lifetime. More... | |
| #define | RegisterScopedInterface(container, interface_, implementation, ...) (container).template RegisterScopedService<interface_>(FACTORY(implementation, __VA_ARGS__)) |
| Registers a service with scoped lifetime as an implementation of a specific interface. More... | |
| #define FACTORY | ( | class_, | |
| ... | |||
| ) |
Service factory.
| class_ | the service type |
| ... | the service constructor parameters |
| #define FROM_DI | ( | class_ | ) | (c.template GetRequiredService<class_>()) |
Injects a required service from a DI container.
| class_ | service type |
The service will be injected as a std::shared_ptr. If the service is not registered, an exception will be thrown.
This macro is intended for use as a service constructor argument for the following macros:
| #define FROM_DI_MULTIPLE | ( | class_ | ) | (c.template GetServices<class_>()) |
Injects multiple instances of a service from a DI container.
| class_ | service type |
The service will be injected as a std::vector< std::shared_ptr<> >. If the service is not registered, an empty std::vector< std::shared_ptr<> > will be injected.
This macro is intended for use as a service constructor argument for the following macros:
| #define FROM_DI_OPTIONAL | ( | class_ | ) | (c.template GetService<class_>()) |
Injects an optional service from a DI container.
| class_ | service type |
The service will be injected as a std::shared_ptr. If the service is not registered, an empty std::shared_ptr will be injected.
nullptr or a factory function that returns nullptr.This macro is intended for use as a service constructor argument for the following macros:
| #define RegisterScopedInterface | ( | container, | |
| interface_, | |||
| implementation, | |||
| ... | |||
| ) | (container).template RegisterScopedService<interface_>(FACTORY(implementation, __VA_ARGS__)) |
Registers a service with scoped lifetime as an implementation of a specific interface.
| container | DI container |
| interface_ | interface type |
| implementation | type of the implementation of the interface |
| ... | service constructor arguments |
A scoped service behaves like a singleton inside its scope and derived scopes.
| #define RegisterScopedService | ( | container, | |
| class_, | |||
| ... | |||
| ) | (container).template RegisterScopedService<class_>(FACTORY(class_, __VA_ARGS__)) |
Registers a service with scoped lifetime.
| container | DI container |
| class_ | service type |
| ... | service constructor arguments |
A scoped service behaves like a singleton inside its scope and derived scopes.
| #define RegisterSharedInterface | ( | container, | |
| interface_, | |||
| implementation, | |||
| ... | |||
| ) | (container).template RegisterSharedService<interface_>(FACTORY(implementation, __VA_ARGS__)) |
Registers a service with shared lifetime as an implementation of a specific interface.
| container | DI container |
| interface_ | interface type |
| implementation | type of the implementation of the interface |
| ... | service constructor arguments |
A shared service exists while it is used. When the shared service is requested, if an instance already exists, that instance is returned; otherwise a new instance is created.
| #define RegisterSharedService | ( | container, | |
| class_, | |||
| ... | |||
| ) | (container).template RegisterSharedService<class_>(FACTORY(class_, __VA_ARGS__)) |
Registers a service with shared lifetime.
| container | DI container |
| class_ | service type |
| ... | service constructor arguments |
A shared service exists while it is used. When the shared service is requested, if an instance already exists, that instance is returned; otherwise a new instance is created.
| #define RegisterSingletonInterface | ( | container, | |
| interface_, | |||
| implementation, | |||
| ... | |||
| ) | (container).template RegisterSingletonService<interface_>(FACTORY(implementation, __VA_ARGS__)) |
Registers a service with singleton lifetime as an implementation of a specific interface.
| container | DI container |
| interface_ | interface type |
| implementation | type of the implementation of the interface |
| ... | service constructor arguments |
A singleton service is created once and used everywhere.
| #define RegisterSingletonService | ( | container, | |
| class_, | |||
| ... | |||
| ) | (container).template RegisterSingletonService<class_>(FACTORY(class_, __VA_ARGS__)) |
Registers a service with singleton lifetime.
| container | DI container |
| class_ | service type |
| ... | service constructor arguments |
A singleton service is created once and used everywhere.
| #define RegisterTransientInterface | ( | container, | |
| interface_, | |||
| implementation, | |||
| ... | |||
| ) | (container).template RegisterTransientService<interface_>(FACTORY(implementation, __VA_ARGS__)) |
Registers a service with transient lifetime as an implementation of a specific interface.
| container | DI container |
| interface_ | interface type |
| implementation | type of the implementation of the interface |
| ... | service constructor arguments |
A transient service is created each time it is requested.
| #define RegisterTransientService | ( | container, | |
| class_, | |||
| ... | |||
| ) | (container).template RegisterTransientService<class_>(FACTORY(class_, __VA_ARGS__)) |
Registers a service with transient lifetime.
| container | DI container |
| class_ | service type |
| ... | service constructor arguments |
A transient service is created each time it is requested.