addTransient
mach::AppBuilder::addTransient
Registers a transient service.
Description
Section titled “Description”Registers a transient service with the DI container.
Syntax
Section titled “Syntax”template <typename T, typename... Deps>AppBuilder& addTransient();Return Value
Section titled “Return Value”A reference to the current AppBuilder instance.
Template Parameters
Section titled “Template Parameters”| Parameter | Description |
|---|---|
T |
The service type to register. |
Deps |
The dependency types used to construct the service. |
Exceptions
Section titled “Exceptions”| Exception | Condition |
|---|---|
std::logic_error |
Thrown if the service type has already been registered or is reserved by the framework. |
Remarks
Section titled “Remarks”A new instance of the service is created each time it is resolved.
Thread Safety
Section titled “Thread Safety”This method is not thread-safe and should only be called during application configuration, before the application starts handling requests.
Example
Section titled “Example”builder.addTransient<EmailSender>();builder.addTransient<NotificationService, EmailSender>();See Also
Section titled “See Also”| Name | Description |
|---|---|
addScoped |
Registers a scoped service. |
addSingleton |
Registers a singleton service. |