Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factory providers #893

Open
subzero911 opened this issue Oct 27, 2024 · 3 comments
Open

Factory providers #893

subzero911 opened this issue Oct 27, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@subzero911
Copy link

Seems like there's currently no possibility to make a provider which returns a new instance every time I access it.

I can do it in get_it:

getIt.registerFactory<MyModel>(() => MyModel());

How about adding it to provider?
It either could be a new FactoryProvider, or a factory: true property to the existing Provider widget.

@rrousselGit
Copy link
Owner

What's the purpose?

@rrousselGit rrousselGit added question Further information is requested and removed needs triage labels Oct 27, 2024
@subzero911
Copy link
Author

subzero911 commented Oct 27, 2024

It might be useful for testing sometimes, like you cannot test if you just spawn RefreshUsecase() in a code.
But you can do it if you registered a factory getIt.registerFactory<RefreshUsecase>(() => MockRefreshUsecase()); and get it through getIt<RefreshUsecase>()

@rrousselGit
Copy link
Owner

I don't think that's quite in the scope of what Riverpod tries to do.
It's a caching package. It feels odd to have a feature where the whole point is to not do caching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants