mikoskinen / Blazor.EventAggregator

Lightweight Event Aggregator for Blazor (Razor Components).
MIT License
120 stars 23 forks source link

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

Open roustan2 opened 4 years ago

roustan2 commented 4 years ago

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

dodyg commented 4 years ago

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>();
AFAde commented 3 years ago

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

ryanbuening commented 3 years ago

@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?

gregoryagu commented 1 year ago

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.