I am building my first RiverPod based Flutter app, and I'm trying to understand how RiverPod works with the service and repository pattern.
I have a repository class that owns the task of handling interactions with a particular storage API, in this case it can either be FireStore or Hive according to user configuration.
There is a separate service class that acts as the logical tier for persisting data, like...
final goalRepositoryProvider = Provider<FsGoalRepository>((ref)=> FsGoalRepository());
class GdGoalService {
Future<GdGoal> add(GdGoal aNewGoal) async {
return ref.watch(goalRepositoryProvider).add(aNewGoal);
}
...
}
Problem is, I can't find a way of setting the 'ref' value into the service class. In essence, I am trying to use RiverPod to dependency inject the repository class into the service.
Is passing the 'ref' as a parameter to the service a legitimate approach?
final goalServiceProvider = Provider<GdGoalService >((ref) {
return GdGoalService (ref);
});
Suggestions?