Blazor.EventAggregator icon indicating copy to clipboard operation
Blazor.EventAggregator copied to clipboard

services.AddSingleton<IEventAggregator, EventAggregator.Blazor.EventAggregator>(); ???

Open roustan2 opened this issue 4 years ago • 4 comments

Hi, Are you sure to register as singleton is a good way ? In this case all clients will receive notification on their pages.

roustan2 avatar Mar 10 '20 13:03 roustan2

Yeah this makes using services.AddEventAggregator(); make the whole library unusable for Blazor Server Side.

The workaround is to use this instead at ConfigureServices

services.AddScoped<EventAggregator.Blazor.IEventAggregator, EventAggregator.Blazor.EventAggregator>();

dodyg avatar May 26 '20 11:05 dodyg

Hi @mikoskinen, I am sharing the same concerns as the two other developers. For Blazor Server Side, normally you would use it as a scoped service. Would it make sense to make the registration type configurable?

Thanks

AFAde avatar Nov 18 '20 09:11 AFAde

@mikoskinen, @dradovic are you accepting PR's to fix this scope issue for Blazor Server?

Also, with the current library, how can I use:

services.AddScoped<EventAggregator.Blazor.IEventAggregator, EventAggregator.Blazor.EventAggregator>();

and set AutoRefresh = true?

ryanbuening avatar Jul 26 '21 13:07 ryanbuening

It is unexpected to be a singleton, instead of scoped. I also vote to change this. It's a super easy fix, no reason not to.

gregoryagu avatar Nov 21 '22 15:11 gregoryagu