How to properly pass dependencies in v3 #4397
Unanswered
DirtyNative
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am coming from a constructor dependency injection world and see the benefits of it, but I am open to new thoughts. In Riverpod v2 I was able to do something like this:
final audioImportStateNotifierProvider = StateNotifierProvider<AudioImportStateNotifier, AsyncValue>((ref) {
return AudioImportStateNotifier(
ref.watch(loadActiveImportOperationsUseCaseProvider),
ref.watch(loadActiveImportBatchesUseCaseProvider),
ref.watch(audioFileImportRepositoryProvider),
ref.watch(updateImportBatchUseCaseProvider),
ref.watch(libraryStateNotifierProvider.notifier),
ref.watch(loggerProvider),
);
});
class AudioImportStateNotifier extends StateNotifier<AsyncValue> {
final LoadActiveImportOperationsUseCase _loadOperationsUseCase;
final LoadActiveImportBatchesUseCase _loadBatchesUseCase;
final AudioFileImportRepositoryPort _importRepository;
final UpdateImportBatchUseCase _updateBatchUseCase;
final LibraryStateNotifier _libraryStateNotifier;
final Logger _logger;
AudioImportStateNotifier(
this._loadOperationsUseCase,
this._loadBatchesUseCase,
this._importRepository,
this._updateBatchUseCase,
this._libraryStateNotifier,
this._logger,
)
But this no longer works in v3 it seems. What would be the proper way to pass the dependencies in v3 without losing the benefits constructor injection offers?
Beta Was this translation helpful? Give feedback.
All reactions