API Reference
Complete API documentation for all Nest Dart packages.
nest_core
ApplicationContainer
The central container that manages modules and services.
Code
Methods
registerModule
Code
Register a module with the container.
Parameters:
module
: The module to register
Example:
Code
registerModules
Code
Register multiple modules at once.
get
Code
Get a service instance from the container.
Type Parameters:
T
: The service type to retrieve
Parameters:
instanceName
: Optional instance name for named registrations
Returns: Service instance of type T
Throws: ServiceNotExportedException
if service is not accessible
getWithParams
Code
Get a service instance with constructor parameters.
getAsync
Code
Get an async service instance.
isRegistered
Code
Check if a service is registered and accessible.
getAvailableServices
Code
Get all services available to the root container.
waitUntilReady
Code
Wait for the container to be fully initialized.
allReady
Code
Wait for all services to be ready.
reset
Code
Reset the container, destroying all modules and services.
Properties
isReady
Code
Whether the container is fully initialized.
modules
Code
List of all registered modules.
context
Code
The module context for debugging and testing.
getIt
Code
Access to the underlying GetIt instance (use with caution).
Module
Abstract base class for all modules.
Code
Properties
imports
Code
List of modules that this module depends on.
exports
Code
List of service types that this module exports to other modules.
Methods
providers
Code
Configure services for dependency injection. Must be implemented by subclasses.
Parameters:
locator
: The service locator for registering services
onModuleInit
Code
Called after module registration and dependency resolution.
onModuleDestroy
Code
Called when the module is being destroyed/reset.
Locator
Interface for dependency injection container operations.
Code
Methods
get / call
Code
Get a service instance. call
is syntactic sugar for get
.
registerSingleton
Code
Register a singleton instance.
Parameters:
instance
: The service instanceinstanceName
: Optional name for the instancesignalsReady
: Whether the instance signals when readydispose
: Optional disposal function
registerFactory
Code
Register a factory function that creates new instances each time.
registerLazySingleton
Code
Register a lazy singleton that's created on first access.
ModuleContext
Context for tracking module dependencies and exports.
Code
Exceptions
ServiceNotExportedException
Code
Thrown when trying to access a service that hasn't been exported by its module.
nest_flutter
ModularApp
Widget that initializes the dependency injection container.
Code
Properties
module
Code
The root module to initialize.
child
Code
The child widget to wrap.
container
Code
Optional custom container instance.
ApplicationContainerProvider
InheritedNotifier that provides ApplicationContainer to the widget tree.
Code
Static Methods
of
Code
Get the ApplicationContainerNotifier from the widget tree.
maybeOf
Code
Get the ApplicationContainerNotifier or null if not found.
containerOf
Code
Get the ApplicationContainer from the widget tree.
maybeContainerOf
Code
Get the ApplicationContainer or null if not found.
ApplicationContainerNotifier
ChangeNotifier wrapper for ApplicationContainer.
Code
Properties
container
Code
The underlying container instance.
Methods
registerModule
Code
Register a module without notification.
registerModuleWithNotification
Code
Register a module and notify listeners.
get
Code
Get a service instance.
reset
Code
Reset the container and notify listeners.
Modular (Flutter)
Static class providing service access in Flutter apps.
Code
nest_frog
Modular (Frog)
Static class providing service access in Dart Frog apps.
Code
Methods
initialize
Code
Initialize the application container with the root module.
of
Code
Get a context-aware service accessor.
get
Code
Get a service directly from the container.
ModularContext
Context wrapper for request-scoped service access.
Code
Methods
get
Code
Get a service from the request context, with fallback to container.
has
Code
Check if a service is available in the context.
nestFrogMiddleware
Middleware factory for Dart Frog integration.
Code
Creates middleware that initializes the container and provides dependency injection.
Parameters:
appModule
: The root module to initialize
Returns: Dart Frog middleware
Example:
Code
Type Definitions
FactoryFunc
Code
Function that creates service instances.
DisposingFunc
Code
Function called when disposing service instances.
Constants and Enums
Service Registration Types
Services can be registered in three ways:
- Singleton: Created once and reused (
registerSingleton
) - Factory: New instance created each time (
registerFactory
) - Lazy Singleton: Created on first access (
registerLazySingleton
)
Access Levels
Services have different access levels:
- Private: Only accessible within the same module
- Exported: Accessible by modules that import the providing module
- Global: Accessible from the root container (auto-exported)
Error Codes
ServiceNotExportedException
Thrown when attempting to access a service that hasn't been exported.
Common causes:
- Service not listed in module's
exports
- Module not imported by the requesting module
- Typo in service type
Resolution:
- Add service to module's
exports
list - Import the providing module
- Check service type spelling
Circular Dependency Detection
Nest Dart automatically detects and prevents circular dependencies during module registration.
Resolution:
- Restructure modules to avoid circular imports
- Extract common dependencies to a shared module
- Use lazy loading for optional dependencies
Migration Guide
From GetIt Direct Usage
Before:
Code
After:
Code
From Provider Package
Before:
Code
After:
Code
Best Practices
Module Organization
- Group related services in the same module
- Keep modules focused on a single domain
- Use clear, descriptive module names
Service Registration
- Prefer singletons for stateless services
- Use factories for stateful or short-lived services
- Register interfaces, not implementations when possible
Error Handling
- Always handle
ServiceNotExportedException
- Use try-catch blocks in service methods
- Provide meaningful error messages
Testing
- Create test modules with mock services
- Use
ApplicationContainer.reset()
in test teardown - Test module initialization and lifecycle hooks
Performance
- Use lazy singletons for expensive services
- Dispose of resources in module destroy hooks
- Monitor container initialization time