addController
mach::AppBuilder::addController
Registers a HTTP controller.
Description
Section titled “Description”Registers a HTTP controller with the dependency injection container.
Syntax
Section titled “Syntax”template <typename T, typename... Deps>AppBuilder& addController();Return Value
Section titled “Return Value”A reference to the current AppBuilder instance.
Template Parameters
Section titled “Template Parameters”| Parameter | Description |
|---|---|
T |
The controller type to register. |
Deps |
The dependency types used to construct the controller. |
Exceptions
Section titled “Exceptions”| Exception | Condition |
|---|---|
std::logic_error |
Thrown if the controller type has already been registered or is reserved by the framework. |
Remarks
Section titled “Remarks”Controllers are registered with a transient lifetime. A new controller instance is created for each request that invokes the controller.
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.addController<UserController, UserRepository>();See Also
Section titled “See Also”| Name | Description |
|---|---|
ControllerBuilder |
Configures routes for a controller. |
ControllerBase |
Base class for defining controllers. |
addTransient |
Registers a transient service. |