initialize abstract method

Future<void> initialize({
  1. required AuthServiceInt authService,
})

Initializes DeviceService with auth reference for race-free setup.

Call this AFTER creating AuthService with callbacks pre-registered. This sets up the auth reference and lifecycle service connection without registering callbacks (since they were passed to AuthService).

Critical Constraint

The implementation MUST set _authService synchronously at the start, before any await statements. This ensures the auth reference is available when callbacks fire (which may happen via microtask immediately after AuthService construction).

Usage

// Race-free initialization pattern:
final deviceService = DeviceServiceImpl();
final auth = AuthServiceImpl(
  firebaseApp: app,
  onAuthenticatedCallbacks: [deviceService.handleAuthenticated],
  onAboutToLogOutCallbacks: [deviceService.handleAboutToLogOut],
);

// CRITICAL: Use Future.wait for parallel initialization
await Future.wait([
  deviceService.initialize(authService: auth),
  notificationService.initialize(authService: auth),
]);

Parameters

  • authService: The AuthService instance to connect to.

Implementation

Future<void> initialize({required AuthServiceInt authService});