AddSingleton behave like Scoped

Hello Support Team,

Within the attached solution, I have two projects. Both are Blazor Webassembly Standalone App. The first project called SfBlazorStandaloneIssue has been generated by your Syncfusion Blazor Template Studio V 26.2.4, while the second project called VsBlazorStandaloneApp has been generated by the normal VS2022 wizard.

In both projects:

  • I added a simple CounterServices.cs class which increments a counter.
  • I registered this class with AddSingleton() because I wanted to share the value of the counter on all pages.
  • I injected the CounterServices in both Counter.razor and Weather.razor pages.


What I do not understand is:

  • With the  VsBlazorStandaloneApp project, If I navigate between Counter and Weather pages and increment the counter value in one or the other page, the value is kept as expected (remember, the service is  Singleton).
  • But with the  SfBlazorStandaloneIssue project, the counter value is reseted ... Sounds like the service is not a Singleton.


Can you please provide a support. What I'm doing wrong?

Thank you in advance.

Artilizansa.


Attachment: SfBlazorStandaloneIssue_b3e0e47.zip

2 Replies

AR Artilizansa August 29, 2024 09:58 AM UTC

Update

I understood what causes this behavior. If you navigate between Counter and Weather pages by clicking their corresponding items on the navmenu, then the application stays on the same circuit, so the Standalone service is kept. But if you enter manually the url of the Counter and/or the Weather page, then the application starts a new circuit therefore all services are re-instanciated again.

Finally there is no issue.


Sorry for this ticket.

Artilizansa.



SK Subathra Kaliamoorthy Syncfusion Team August 30, 2024 01:53 PM UTC

Hi Artilizansa,


We are glad to know that your issue has been resolved. Please get back to us if you need any other assistance.


Regards,

Subathra K


Loader.
Up arrow icon