Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Struggling to integrate ReactiveUi with Blazor#3852

Unanswered
Jejuni asked this question inQ&A
Discussion options

I come from an Angular background and highly enjoy working in a reactive way and really dislike the way Blazor does things (but have to use it).
Rx.NET and ReactiveUI seem like the perfect combination to make me happy, but I'm having trouble integrating the libraries in a way that doesn't make me fight Blazor too much (and usually when you're fighting with your main framework you're doing something wrong).

In particular I'm having trouble with Blazor[Parameter]s.

The current use-case I wanted to implement was simply reacting to route param changes in my ViewModel.
Given a route template in the form ofusers/{id:guid} I simply want theid in my view model.

The default way is to put a[Parameter] on your component with a name matching the route value.
Now I've already written an observable wrapper aroundNavigationManager that does the parsing for me and returns anIObservable<string> given a route template and route param name.
The problem is BlazorALWAYS expects there to be a[Parameter] with a matching name if you have a param in your route.
That sucks.

But to me, this is a more general problem:

How do I deal with Blazor's[Parameter] and the way Blazor expects me to do things when I have a ViewModel? BlazorREALLY wants you to implement all[Parameter]s as auto-properties with nothing added to the setter and getter (although I don't really know why). It goes as far as issuing a warning if you don't use auto-properties.

I really don't want to go the way ofOnParametersSet with the ViewModel, which would be the Blazor default way to handle executing something when a parameter changes. I could of course use this pattern to put the[Parameter] values into my ViewModel... but then they'd already be on the View, so what am I even using the ViewModel for?

Should I just adopt above pattern and keep[Parameter]s exclusively in the view and useOnParametersSet where I call a ViewModel command with a parameter when I need the functionality? Is that really the way?

I really hope someone can give me some guidance or point me towards an article or a large code base using Blazor + ReactiveUI successfully.

You must be logged in to vote

Replies: 2 comments

Comment options

Blazor has been quite fluid since it's release so I understand the frustration of having to use it.
Not many people have mentioned any issues with ReactiveUI Blazor so am glad to get some feedback. I am guessing that the decorators for [Parameter] indicates that a source generator is being used hence the requirement for a auto get/set property. If this is now the case we may need to consider creating a [ReactiveParameter] decorator and having a source generator to satisfy both Blazor and ReactiveUI.
I personally wanted to use Blazor for a few projects since it's initial release but found to many limitations to make it viable.
But there's definitely a good number of people who are using it.
I will try to research the actual methodology used in Blazor in the current version and see what is required to allow ReactiveUI to operate as expected.
I believe there's a few project types using Blazor which way are you wanting to use?

You must be logged in to vote
0 replies
Comment options

Thanks a lot for the insight.

The[Parameter] type attributes might be source generators, but maybe they're also just using cached reflection. Not quite sure on that one.
And it's absolutely true Blazor has been very fluid - we've had our functionality break once they introduced their major changes with .NET 8 and had to re-design authentication because of it. To be completely fair to Blazor, though, there are also very enjoyable parts about it. As a full stack C# developer the code sharing is amazing - from simple models to source generators that react to changes in the frontend and implement something in the backend. That's really cool.

What we're using right now is the .NET 8 version of Blazor. The template for it is "Blazor Web App, WebAssembly, Global Interactivity".
Although I believe that the same problem/solution would also apply to the Server version, WebAssembly standalone, as well as previous versions. Although the previous versions ("Hosted on ASP.NET Core", etc) are pretty much deprecated, I can't even find the template in my VS anymore.

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@Jejuni@ChrisPulman

[8]ページ先頭

©2009-2025 Movatter.jp