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
fix: hot reload makes instance registered twice when using get_it package #335
Comments
Hi @ekokurniadi 👋 I’ll take a closer look at this shortly but out of curiosity was there any specific reason why you decided to include get_it instead of using the built in provider API for dependency injection? Thanks! 🙏 |
Hi @felangel |
Hi @felangel |
Did you manage to resolve the issue? |
I had same situation. The "problem" is about hot reload, after changes, reload everything, even the "init()". For now, I figured out 2 workarounds options to handle this for me.
Future<void> init() async {
if (_didSetup) return;
_didSetup = true;
...
if (!GetIt.I.isRegistered<MySingleton>()) {
GetIt.I.registerLazySingleton<MySingleton>();
} |
I'm going to re-open this since it sounds like something that should be supported by Dart Frog's hot reload. |
I've encountered this problem recently, and as @GabrielRozendo stated, it only occurs after hot reloads. Future<HttpServer> run(Handler handler, InternetAddress ip, int port) async {
await GetIt.I.reset();
configureDependencies();
return serve(handler, ip, port);
} I'm using Injectable instead of the built in provider API because it simplifies working in multiple environments, and also because of periodic jobs runners that don't have access to a context to read from. |
related to fluttercommunity/get_it#166 |
I used the same get it verifier as you and it did the trick. |
Closing for now since this does not appear to be directly related to Dart Frog. As folks have mentioned, you can check if an object has been registered already to prevent re-registering. |
Description
I have some problem when i registered object or instance using get_it, when server is hot reloaded get_it re-registered instance make server stop running
Steps To Reproduce
Expected Behavior
Instance registered only once
A clear and concise description of what you expected to happen.
Screenshots
My Get It
My Custom Entry Point
If applicable, add screenshots to help explain your problem.
Additional Context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: