initialize static method

void initialize({
  1. String? huggingFaceToken,
  2. int maxDownloadRetries = 10,
  3. FileSystemService? fileSystemService,
  4. AssetLoader? assetLoader,
  5. DownloadService? downloadService,
  6. ModelRepository? modelRepository,
  7. 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 downloads
  • maxDownloadRetries: 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,
  );
}