Skip to content
Download

addController

mach::AppBuilder::addController

Registers a HTTP controller.

Registers a HTTP controller with the dependency injection container.

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

A reference to the current AppBuilder instance.

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

Controllers are registered with a transient lifetime. A new controller instance is created for each request that invokes the controller.

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

builder.addScoped<UserRepository>();
builder.addController<UserController, UserRepository>();
Name Description
ControllerBuilder Configures routes for a controller.
ControllerBase Base class for defining controllers.
addTransient Registers a transient service.