pub struct NestForgeFactory<M: ModuleDefinition> { /* private fields */ }Expand description
The main entry point for creating a NestForge application.
It handles the bootstrap process:
- Creating the DI Container.
- Initializing the Module Graph (resolving imports and providers).
- Merging all Controller routers into a single Axum app.
- Attaching global middleware, guards, interceptors, and exception filters.
§Example
use nestforge_http::NestForgeFactory;
#[tokio::main]
async fn main() {
let app = NestForgeFactory::<AppModule>::create()
.expect("failed to start")
.listen(3000)
.await;
}Implementations§
Source§impl<M: ModuleDefinition> NestForgeFactory<M>
impl<M: ModuleDefinition> NestForgeFactory<M>
Sourcepub fn create() -> Result<Self>
pub fn create() -> Result<Self>
Creates a new application instance from the root module.
This triggers the DI container initialization and module lifecycle hooks (e.g., on_module_init).
Sourcepub fn with_global_prefix(self, prefix: impl Into<String>) -> Self
pub fn with_global_prefix(self, prefix: impl Into<String>) -> Self
Sets a global prefix for all routes (e.g., “api”).
Sourcepub fn with_version(self, version: impl Into<String>) -> Self
pub fn with_version(self, version: impl Into<String>) -> Self
Sets a global API version for all routes (e.g., “v1”).
Sourcepub fn use_guard<G>(self) -> Self
pub fn use_guard<G>(self) -> Self
Registers a global guard.
Global guards run for every route in the application.
Sourcepub fn use_interceptor<I>(self) -> Selfwhere
I: Interceptor + Default,
pub fn use_interceptor<I>(self) -> Selfwhere
I: Interceptor + Default,
Registers a global interceptor.
Global interceptors wrap every route handler.
Sourcepub fn use_exception_filter<F>(self) -> Selfwhere
F: ExceptionFilter + Default,
pub fn use_exception_filter<F>(self) -> Selfwhere
F: ExceptionFilter + Default,
Registers a global exception filter.
Catches unhandled exceptions from any route.
Sourcepub fn use_middleware<T>(self) -> Selfwhere
T: NestMiddleware + Default,
pub fn use_middleware<T>(self) -> Selfwhere
T: NestMiddleware + Default,
Applies middleware to the application.
Use the builder to select which routes the middleware applies to.
Sourcepub fn configure_middleware<F>(self, configure: F) -> Selfwhere
F: FnOnce(&mut MiddlewareConsumer),
pub fn configure_middleware<F>(self, configure: F) -> Selfwhere
F: FnOnce(&mut MiddlewareConsumer),
Advanced middleware configuration using a consumer builder.
Sourcepub fn with_auth_resolver<F, Fut>(self, resolver: F) -> Self
pub fn with_auth_resolver<F, Fut>(self, resolver: F) -> Self
Sets the authentication resolver.
This function is called for every request to resolve the AuthIdentity
from the bearer token.
Sourcepub fn merge_router(self, router: Router<Container>) -> Self
pub fn merge_router(self, router: Router<Container>) -> Self
Merges an external Axum router into the application.
Useful for integrating other libraries or raw Axum handlers.
Sourcepub fn into_router(self) -> Router
pub fn into_router(self) -> Router
Consumes the factory and returns the fully configured Axum Router.
Use this if you want to run the app with your own server (e.g. Lambda, Shuttle).