Skip to main content
NestFactory is the entry point for every nestrs application. You call one of its static methods with a root module type parameter, and it builds the ProviderRegistry, wires controllers into an Axum Router, and returns either a NestApplication builder or a MicroserviceApplication handle that you configure and then start listening.

NestFactory::create

Creates an HTTP application from a static root module type.
M
impl Module
The root module type. Must implement the Module trait, which is generated by #[module(...)].
M::build() runs at call time: it walks the module import graph, registers all providers into a ProviderRegistry, and registers all controllers into an Axum Router. The returned NestApplication is a builder; no network socket is opened until you call listen, listen_graceful, or listen_with_shutdown.

NestFactory::create_with_modules

Creates an HTTP application from a static root module plus a collection of runtime-selected DynamicModule instances.
M
impl Module
The static root module type.
dynamic_modules
IntoIterator<Item = DynamicModule>
Zero or more dynamic modules to merge into the root module’s registry and router.
Use this when you need to conditionally include feature routers or plug-in modules that are only known at runtime—for example, when a feature flag is read from the environment after startup.

NestFactory::create_microservice (TCP)

Creates a microservice application using the TCP transport adapter. Requires the microservices feature.
M
impl Module + MicroserviceModule
The root module type. Must also implement MicroserviceModule, generated when you declare microservices = [...] in #[module].
options
TcpMicroserviceOptions
TCP server configuration (host, port, and related settings).
Call .also_listen_http(port) on the returned MicroserviceApplication to run both an HTTP router and the microservice transport in a single process (hybrid mode).

NestFactory::create_microservice_nats

Creates a microservice application using the NATS transport adapter. Requires the microservices-nats feature.
options
NatsMicroserviceOptions
NATS connection and subject configuration.

NestFactory::create_microservice_redis

Creates a microservice application using the Redis Pub/Sub transport adapter. Requires the microservices-redis feature.
options
RedisMicroserviceOptions
Redis connection and channel configuration.

NestFactory::create_microservice_grpc

Creates a microservice application using the gRPC transport adapter. Requires the microservices-grpc feature. The gRPC transport carries JSON-encoded payloads (pattern + payload_json) inside protobuf, matching the nestrs-microservices::wire module’s request/response shapes.
options
GrpcMicroserviceOptions
Bind address and TLS configuration for the tonic gRPC server.

NestFactory::create_microservice_rabbitmq

Creates a microservice application using the RabbitMQ transport adapter. Requires the microservices-rabbitmq feature.
options
RabbitMqMicroserviceOptions
AMQP connection URL, exchange, and queue configuration.

MicroserviceApplication builder methods

All create_microservice_* methods return a MicroserviceApplication. It exposes the following builder methods before you call listen: