Refactor Toast Message Manager#1065
Conversation
aaronbrethorst
left a comment
There was a problem hiding this comment.
Hey Mohamed, thanks for taking the time to clean up the ToastManager singleton. Migrating from ToastManager.shared to explicit dependency injection through the Application class is exactly the right direction — it makes the toast system testable, eliminates hidden global state, and aligns with the DI patterns used throughout the rest of the codebase. The change is well-scoped: the @EnvironmentObject wiring is correct, the new var application: Application { get } protocol requirement is cleanly satisfied by both existing conformers (MapViewController and StopViewController), and the hideToastMessage removal is justified since the ToastModifier binding already handles the reset automatically.
There's nothing left to change — this PR is ready to merge. Nice, focused refactoring.
This PR refactors the ToastManager to remove its global singleton (
ToastManager.shared) and migrate the app towards an explicit Dependency Injection (DI) pattern.By tying the ToastManager lifecycle to the Application class and explicitly passing it down the hierarchy
What's Changed
ToastManager. It is now instantiated locally and attached to the coreApplicationinstance.showSuccessToast,showErrorToast) to expect aToastManagerargument. This argument is then passed to the hosting view's environment (.environmentObject(manager)).ToastModifierandToastContainerViewto accept theToastManagervia@EnvironmentObjectinstead of directly referencing@ObservedObject var manager = ToastManager.shared.SurveyViewHostingProtocolto use the injectedapplication.toastManagerwhen posting survey-related feedback toasts.