load<T> method
Load a module by ID
Returns the cached instance if already loaded.
Implementation
Future<T?> load<T>(String moduleId) async {
// Check cache first
if (_loadedModules.containsKey(moduleId)) {
return _loadedModules[moduleId] as T?;
}
final factory = _factories[moduleId];
if (factory == null) {
AirLogger.warning(
'No factory registered for module',
context: {'moduleId': moduleId},
);
return null;
}
try {
final module = await factory.factory();
_loadedModules[moduleId] = module;
AirLogger.debug(
'Loaded federated module',
context: {'moduleId': moduleId, 'package': factory.config.packageName},
);
return module as T?;
} catch (e) {
AirLogger.error(
'Failed to load federated module',
context: {'moduleId': moduleId},
error: e,
);
return null;
}
}