AppBuilder
mach::AppBuilder
Description
Section titled “Description”Builds and configures a Mach application.
Headers
Section titled “Headers”Primary header:
#include <mach/AppBuilder.hpp>Convenience header:
#include <mach/mach.hpp>Syntax
Section titled “Syntax”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();};Constructors
Section titled “Constructors”| Name | Description |
|---|---|
AppBuilder |
Creates a new application builder. |
Member Functions
Section titled “Member Functions”| 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. |
Thread Safety
Section titled “Thread Safety”This class is not thread-safe. Application configuration should be performed from one thread.
Ownership
Section titled “Ownership”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.
Example
Section titled “Example”mach::AppBuilder builder;
// Configure the application.
auto app = builder.build();See Also
Section titled “See Also”| Name | Description |
|---|---|
App |
Represents a configured Mach application. |
AppOptions |
Defines the application’s server configuration options. |