Skip to content
Download

addTransient

mach::AppBuilder::addTransient

Registers a transient service.

Registers a transient service with the DI container.

template <typename T, typename... Deps>
AppBuilder& addTransient();

A reference to the current AppBuilder instance.

Parameter Description
T The service type to register.
Deps The dependency types used to construct the service.
Exception Condition
std::logic_error Thrown if the service type has already been registered or is reserved by the framework.

A new instance of the service is created each time it is resolved.

This method is not thread-safe and should only be called during application configuration, before the application starts handling requests.

builder.addTransient<EmailSender>();
builder.addTransient<NotificationService, EmailSender>();
Name Description
addScoped Registers a scoped service.
addSingleton Registers a singleton service.