© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
1 reply
Sygmond

Is using a blazor component from a service a good idea?

I have a DocumentManagerComponent.razor that is used in multiple places across the app. It has an OnDelete EventCallback that is used for marking a row as deleted and in other places to directly delete a row from database. That depends of the type of page where the component is used, the event it used with different methods.

The lead developer asked to remove this component from everywhere, place it in MainLayout, hook it up with a service (DocumentManagerService) and use this service to manage documents: open, view, edit, delete.

Is this a good idea? Do you see any issues that would result from this?

The initial goal was to have less code for implementing the component but now with a service, it doesn't look as having less code. In fact, moving the delete logic inside the service creates issues with the component not accepting different settings once initially set for a use case, probably because the same instance used for one page can't adapt well to another page where the service is used.

This lead me to subscribe to an event placed inside the service and do the delete logic outside of the service.

I looked around and I couldn't find any example of using a component as a service.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Blazor WASM: Injecting a service
C#CC# / help
15mo ago
blazor service issues
C#CC# / help
2y ago
Blazor Modal Service
C#CC# / help
3y ago
❔ Is saving data from DB into private fields is a good idea?
C#CC# / help
3y ago