I hanve an abstract DataService
which will probably have several implementations. I want to have an implementation that uses LocalStorage
as backend, mainly for testing, and probably a Google and Facebook backend to store my app data:
@Injectable({
providedIn: 'root'
})
abstract class DataService {
abstract get(token: string): Observable<any>
abstract set(token:string, data: any): void
}
@Injectable({
providedIn: 'root'
})
export class LocalDataService implements DataService {
constructor() {}
get(token: string): Observable<string> {
return of(localStorage.getItem(token));
}
set(token: string, data: string): void {
localStorage.setItem(token, data);
}
}
@Injectable({
providedIn: 'root'
})
export class GDriveDataService implements DataService {...}
@Injectable({
providedIn: 'root'
})
export class FacebookDataService implements DataService {...}
My problem is that I can only know which implementation to use after the user logs in with either Google or Facebook account.
Is it possible to switch the provided impmlementation of the Service after tha app has been bootstrapped? Do I need to take a different approach?