addScoped
mach::AppBuilder::addScoped
Registers a scoped service.
Description
Section titled “Description”Registers a scoped service with the DI container.
Syntax
Section titled “Syntax”template <typename T, typename... Deps>AppBuilder& addScoped();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 single instance of the service is created per request and shared by all consumers that resolve it during that request.
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.addScoped<UserRepository>();builder.addScoped<UserService, UserRepository>();See Also
Section titled “See Also”| Name | Description |
|---|---|
addSingleton |
Registers a singleton service. |
addTransient |
Registers a transient service. |