Skip to content
Download

AppBuilder

mach::AppBuilder

Builds and configures a Mach application.

Primary header:

#include <mach/AppBuilder.hpp>

Convenience header:

#include <mach/mach.hpp>
class AppBuilder {
public:
explicit AppBuilder();
template <typename T, typename... Deps>
AppBuilder& addScoped();
template <typename T, typename... Deps>
AppBuilder& addSingleton();
template <typename T, typename... Deps>
AppBuilder& addTransient();
template <typename T, typename... Deps>
AppBuilder& addController();
template <typename T, typename... Deps>
AppBuilder& use();
template <typename TConfigure>
AppBuilder& configureApp(TConfigure&& configure);
template <typename TConfigure>
AppBuilder& configureLogging(TConfigure&& configure);
template <typename TConfigure>
AppBuilder& addCors(TConfigure&& configure);
AppBuilder& addCsrf();
template <typename TConfigure>
AppBuilder& addCsrf(TConfigure&& configure);
[[nodiscard]] App build();
};
Name Description
AppBuilder Creates a new application builder.
Name Description
addScoped Registers a scoped service.
addSingleton Registers a singleton service.
addTransient Registers a transient service.
addController Registers a HTTP controller.
use Registers a middleware.
configureApp Configures the application’s settings.
configureLogging Configures the application’s logging options.
addCors Adds CORS support to the application.
addCsrf Adds CSRF protection to the application.
build Builds the application.

This class is not thread-safe. Application configuration should be performed from one thread.

An AppBuilder instance owns the application’s configuration state until build() is called.

Calling build() transfers the configured runtime state to the resulting App instance. After that, the builder should not be used for further configuration.

mach::AppBuilder builder;
// Configure the application.
auto app = builder.build();
Name Description
App Represents a configured Mach application.
AppOptions Defines the application’s server configuration options.