Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Choice between using Singleton or Scoped events #9

Open
ZwapKillrath opened this issue Oct 4, 2024 · 2 comments
Open

Choice between using Singleton or Scoped events #9

ZwapKillrath opened this issue Oct 4, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@ZwapKillrath
Copy link
Collaborator

New Feature Proposal

Choice between using the global events or a "local" (scoped) version of the event handler.

Description

Having the need for scoped events to send/receive messages in a single users session and not all users at the same time.
As we know, Blazor server Singleton registration is shared for all circuits.
Not all use cases involve that, so a scoped version should be available as well.

Maybe something like having two interfaces ISingletonEvents, IScopedEvents and a class PiralEvents
PiralEvents : IScopedEvents, ISingletonEvents

Then in the registration:
services.AddScoped<IScopedEvents, PiralEvents>();
services.AddSingleton<ISingletonEvents, PiralEvents>();

Then in the component do:
@Inject IScopedEvents myEvents
or
@Inject ISingletonEvents myEvents

Should be flexible enough.

Thoughts?

Background

N/A

Discussion

N/A

@ZwapKillrath ZwapKillrath added the enhancement New feature or request label Oct 4, 2024
@FlorianRappl
Copy link
Contributor

Sounds good to me. I think having the scoped events handled via injection makes sense. This way, it would not conflict with the micro frontend API (and events).

IScopedEvents makes sense - ISessionEvents maybe, too. The current / singleton events I would keep on the service API (i.e,., IEvents - even though the interface is never implemented explicitly).

@ZwapKillrath
Copy link
Collaborator Author

Hi,
Do you have a timeframe for the above implementation in Piral?
/ZwapKillrath

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants