nest_frog library
Dart Frog integration for Nest Dart - bringing dependency injection and modular architecture to Dart Frog backend applications.
This library provides Dart Frog-specific middleware and utilities for the Nest Dart framework, and re-exports all core functionality from nest_core for convenience.
Classes
- ApplicationContainer
- Application container that manages modules and dependency injection Provides centralized service resolution with module-based encapsulation
- Disposable
- If objects that are registered inside GetIt implements Disposable the onDispose method will be called whenever that Object is unregistered, reset or its enclosing Scope is popped
- GetIt
- Very simple and easy to use service locator You register your object creation factory or an instance of an object with registerFactory, registerSingleton or registerLazySingleton And retrieve the desired object using get or call your locator as function as its a callable class Additionally GetIt offers asynchronous creation functions as well as functions to synchronize the async initialization of multiple Singletons
- InitDependency
- Data structure used to identify a dependency by type and instanceName
- Locator
- Interface for dependency injection container Provides type-safe access to services with export restrictions
- Modular
- Unified Modular class for Dart Frog integration Combines container management with context-based service access
- ModularContext
- Context wrapper that provides service access
- Module
- Abstract base class for all modules in the framework Provides modular dependency injection with controlled service access
- ModuleContext
- Context for tracking module dependencies and exports
-
ObjectRegistration<
T extends Object> - ShadowChangeHandlers
-
If an object implements the
ShadowChangeHandlerif will get notified if an Object with the same registration type and name is registered on a higher scope which will shadow it. It also will get notified if the shadowing object is removed from GetIt - WillSignalReady
-
If your singleton that you register wants to use the manually signalling
of its ready state, it can implement this interface class instead of using
the
signalsReadyparameter of the registration functions (you don't really have to implement much ;-) )
Enums
- ObjectRegistrationType
-
You will see a rather esoteric looking test
(const Object() is! T)at several places. It tests ifTis a real type and not Object or dynamic. For each registered factory/singleton an ObjectRegistration<T> is created it holds either the instance of a Singleton or/and the creation functions for creating an instance whengetis called
Functions
-
nestFrogMiddleware(
Module appModule) → Middleware - Create NestFrog middleware for Dart Frog This middleware initializes the container and provides dependency injection
-
throwIf(
bool condition, Object error) → void - Two handy functions that help me to express my intention clearer and shorter to check for runtime errors
-
throwIfNot(
bool condition, Object error) → void
Typedefs
-
DisposingFunc<
T> = FutureOr Function(T param) -
Signature for disposing function
because closures like
(x){}have a return type of Null we don't useFutureOr<void> -
FactoryFunc<
T> = T Function() - Signature of the factory function used by non async factories
-
FactoryFuncAsync<
T> = Future< T> Function() - Signature of the factory function used by async factories
-
FactoryFuncParam<
T, P1, P2> = T Function(P1 param1, P2 param2) -
For Factories that expect up to two parameters if you need only one use
voidfor the one you don't use -
FactoryFuncParamAsync<
T, P1, P2> = Future< T> Function(P1 param1, P2 param2) -
For async Factories that expect up to two parameters if you need only one use
voidfor the one you don't use - ScopeDisposeFunc = FutureOr Function()
- Signature for disposing function on scope level
Exceptions / Errors
- ServiceNotExportedException
- Exception thrown when trying to access a non-exported service
- WaitingTimeOutException