Skip to content
Download

addScoped

mach::AppBuilder::addScoped

Registers a scoped service.

Registers a scoped service with the DI container.

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

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 single instance of the service is created per request and shared by all consumers that resolve it during that request.

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

builder.addScoped<UserRepository>();
builder.addScoped<UserService, UserRepository>();
Name Description
addSingleton Registers a singleton service.
addTransient Registers a transient service.