© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
4 replies
Saiyanslayer

Blazor Design: Expression Service That Depends on other Objects

For a Blazor project, I have a group of Expression components that calculates values based on text input and referencing each other for values. Users can use a tag like [value1] to reference other components. For example,
var formula = "[value] + [value2]";
var formula = "[value] + [value2]";

I'm considering using a service to handle this

public List<Component> Components {get;set;}
...
public OnComponentInitializing(Component reference){
  Component.Add(reference);
}

public OnComponentDisposal(Component reference){
  Component.Remove(reference);
}
...

public double GetValue(string tag){
  //converts tag into a label
  //search list for a component that matches the label
  //if found returns the value
}
public List<Component> Components {get;set;}
...
public OnComponentInitializing(Component reference){
  Component.Add(reference);
}

public OnComponentDisposal(Component reference){
  Component.Remove(reference);
}
...

public double GetValue(string tag){
  //converts tag into a label
  //search list for a component that matches the label
  //if found returns the value
}

What I'm worried about is if I have a directory page to search groups, I could end up loading dozens of this service and it could cause issues.

Question: do I have the right approach? Can I use a service to have a group of components to register with it to be easily searched and not have it balloon into a mess? Or should the service be like a singleton and have a single instance and the grouped expressions register and then handle referencing? If not, what would be a cleaner approach?

Alternatively, I was thinking of making a Parent reference in each of the expression components that would reference the group. Then the group would have a method to handle the expression.
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

Service Design
C#CC# / help
11mo ago
blazor service issues
C#CC# / help
2y ago
Blazor Modal Service
C#CC# / help
3y ago
✅ Creating interactive objects in Blazor
C#CC# / help
2y ago