nestrs-core is the foundational crate that every nestrs crate depends on. It provides the compile-time DI container, the runtime module graph, route and metadata registries, and all core traits that guards, pipes, interceptors, and filters implement. You rarely use nestrs-core directly—nestrs re-exports everything under nestrs::core and nestrs::prelude—but understanding the types here helps you extend the framework.
ProviderRegistry
The DI container. Built by #[module]-generated code, it stores one entry per registered type and resolves instances by TypeId.
Registration methods
Resolution
Lifecycle methods
The framework calls these in order insidelisten / listen_graceful:
Introspection
Cross-module absorption
ProviderScope
Controls the lifetime of a provider instance.
register_use_factory:
Injectable trait
Every provider type implements this trait (usually generated by #[injectable]).
construct is always synchronous. Perform async initialization in on_module_init, which runs before the server accepts traffic.Module trait
Generated by #[module]. Called once by NestFactory::create to build the full provider and router graph.
Controller trait
Generated by #[controller] + #[routes]. Registers Axum routes into the router for a module.
ModuleRef
The NestJS ModuleRef analogue. Provides typed access to the root ProviderRegistry after the application graph is built. Obtain it from NestApplication::module_ref().
DiscoveryService
The NestJS DiscoveryService analogue. Introspects registered providers and compiled HTTP routes.
Unlike NestJS, there is no reflection over arbitrary class metadata. You get
TypeId keys, type name strings, and whatever is in the global RouteRegistry. There is no runtime annotation discovery for arbitrary field metadata.RouteRegistry
A process-wide registry populated by impl_routes! / #[routes] expansion at startup. Used by nestrs-openapi to generate the OpenAPI spec.
MetadataRegistry
A process-wide key-value store for handler string metadata set by #[set_metadata] and #[roles].
HandlerKey in request extensions:
ExecutionContext
The NestJS ArgumentsHost analogue for HTTP requests. Available via the HttpExecutionContext extractor when NestApplication::use_execution_context() is enabled.
CanActivate trait
The guard contract. Implement this on any unit struct (must be Default) and apply with #[use_guards].
PipeTransform trait
The pipe contract. ValidationPipe is the built-in implementation.
AuthStrategy trait
Pluggable authentication strategy for AuthStrategyGuard. Implement this to verify tokens, sessions, or API keys.
DynamicModule and DynamicModuleBuilder
Runtime-composed module units for conditional imports, feature flags, and configurable modules.
DynamicModuleBuilder allows provider overrides before controllers are registered (useful for configurable modules and test setups):
ConfigurableModuleBuilder is the NestJS forRoot / forRootAsync pattern: