initialize static method
void
initialize({
- String? huggingFaceToken,
- int maxDownloadRetries = 10,
- FileSystemService? fileSystemService,
- AssetLoader? assetLoader,
- DownloadService? downloadService,
- ModelRepository? modelRepository,
- ProtectedFilesRegistry? protectedFilesRegistry,
Initializes the singleton instance
Call this once at app startup, before using instance. Multiple calls to initialize() are safe - subsequent calls are ignored.
Parameters:
huggingFaceToken
: Optional HuggingFace API token for authenticated downloadsmaxDownloadRetries
: Maximum retry attempts for transient errors (default: 10) Note: Auth errors (401/403/404) fail after 1 attempt regardless- Services can be overridden for testing (dependency injection)
Implementation
static void initialize({
String? huggingFaceToken,
int maxDownloadRetries = 10,
FileSystemService? fileSystemService,
AssetLoader? assetLoader,
DownloadService? downloadService,
ModelRepository? modelRepository,
ProtectedFilesRegistry? protectedFilesRegistry,
}) {
// Make idempotent - skip if already initialized
if (_instance != null) {
debugPrint('ServiceRegistry: Already initialized, skipping re-initialization');
return;
}
_instance = ServiceRegistry._(
huggingFaceToken: huggingFaceToken,
maxDownloadRetries: maxDownloadRetries,
fileSystemService: fileSystemService,
assetLoader: assetLoader,
downloadService: downloadService,
modelRepository: modelRepository,
protectedFilesRegistry: protectedFilesRegistry,
);
}