Closed chumanevros closed 5 years ago
I can't replicate the problem: I made an async method awaiting an http call and I've been able to show a toast before and after the remote call. Can you please point me to a sample of the issue or provide the steps needed to replicate it?
Thank you for the response @ghidello . I think I can better explain what I have found.
I have created a test project, and it looks like when the Toaster gets injected into the class, that the reference to the UI has an issue. It may very well be how the dependency injection works or where in the life cycle this happens.
If I pass the Toaster from the index.razor page into the class, it works. If I use dependency injection with a singleton for my Test : ITest class where I inject the Toaster and then call it , it does not display the Toaster.
https://github.com/chumanevros/ToasterIssue.git
Your thoughts?
Try registering your ITest service as scoped instead of singleton: the AddToaster method registers the IToaster service as scoped (which for client side blazor is the same as singleton) and there are issues calling a scoped service from a singleton one.
Oh and thanks to you for taking the time for creating a test project!
Thank you for the response. Have tested and it works!
The Toaster messages do not display when called from within an async / await method.