Giter Site home page Giter Site logo

mvvmblazor's Introduction

MvvmBlazor

Build Status NuGet NuGet

MvvmBlazor is a small framework for building Blazor WebAssembly and Blazor Server apps. With its easy-to-use MVVM pattern you can increase your development speed while minimising the effort required to make it work.

Getting started

MvvmBlazor is available on NuGet. You will need .NET 6 to use this library.

The library needs to be added to the DI container in order to use it. This is done in your Startup class.

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvvm();
    }
}

Usage

Components

Components need to inherit the base class MvvmBlazor.Components.MvvmComponentBase if you want to inject your view model manually. You can set a binding on any view model you like to.

If you want full support use MvvmBlazor.Components.MvvmComponentBase<T> and specify your view model type as a generic argument. Your view model will get auto injected into the component and set as a binding context.

BindingSource

The binding source is the default source object a binding will be made to. It is set automatically when using the base class MvvmBlazor.Components.MvvmComponentBase<T> where T is your view model type. You can access it via the BindingContext property in your component.

Bindings

Bindings are achieved via the Bind method in the component. If the value of the bound property has changed the component will be told to rerender automatically. In this example we assume that the class ClockViewModel has a property called DateTime.

@inherits MvvmComponentBase<ClockViewModel>

Current time: @Bind(x => x.DateTime)

Bindings can also be done by specifying the binding source explicitly:

@inherits MvvmComponentBase
@inject ClockViewModel ClockViewModel

Current time: @Bind(ClockViewModel, x => x.DateTime)

Bindings also handle background updating automatically. No need to invoke the main thread.

Collection Bindings

If you want to have a collection that automatically notifies the component when it has changed you should use one that implements INotifyCollectionChanged, e.g. ObservableCollection<T>.

In List scenarios you often chain view models to achieve bindings for every list element on it's corresponding view model. Given this view models

class MainViewModel
{
    public ObservableCollection<SubViewModel> Items { get; }
}

class SubViewModel
{
    private string _name;
    public string Name
    {
        get => _name;
        set => Set(ref, _name, value);
    }
}

you can use bindings on your sub view models like this

@foreach (var item in Bind(x => x.Items))
{
    <label>@Bind(item, x => x.Name)</label>
}

This way the name of every list item is bound to it's corresponding entry in the view. If you change the name on any list item, it will be changed in the view too.

EventHandlers

Event handles work just the way they work in blazor. When you use the non generic base class you can bind any injected object on them.

@inherits MvvmComponentBase
@inject CounterViewModel CounterViewModel

<button @onclick="@CounterViewModel.IncrementCount">Click me</button>

When using the generic base class you can directly bind them to your binding context.

@inherits MvvmComponentBase<CounterViewModel>

<button @onclick="@BindingContext.IncrementCount">Click me</button>

ViewModel

View models need to inherit the base class MvvmBlazor.ViewModel.ViewModelBase.

If you register a view model as scoped it will be tied to the lifetime of the component and disposed when the component is disposed. This allows you to inject scoped services that should be short lived (e.g. a DbContext) without the need for using a factory.

Note: Some services need to be resolved from the root service provider (e.g. NavigationManager). To do this you can access the root service provider via the RootServiceProvider property.

Property implementation

Bindable properties need to raise the PropertyChanged event on the ViewModel.

The Set-Method is performing an equality check and is raising this event if needed. An example implementation could look like this:

private int _currentCount;
public int CurrentCount
{
    get => _currentCount;
    set => Set(ref _currentCount, value);
}

As an alternative you can leverage the power of source generators to do the tedious work for you. Just declare a private field inside of a view model and decorate if with the Notify attribute. The matching property will be auto generated for you.

[Notify]
private int _currentCount;

Note: Some third party IDEs may not recognize source generators at the current point. They could report that the property does not exist while the project builds fine.

Lifecycle methods

View models have access to the same lifecycle methods as a component when they are set as a binding context. They are documented here.

Parameters

Parameters are automatically populated to the view model. Declare a parameter in your component

@code {
    [Parameter]
    public string Name { get; set; }
}

and declare the same parameter in your view model

class ViewModel: ViewModelBase
{
    [Parameter]
    public string Name { get; set; }
}

Cascading parameters are supported as well. The parameter will be passed when parameters are set on the component. More information regarding the lifecycle can be found in the Microsoft Documentation .

Type conversion

When binding parameters in a component Blazor restricts you to a finite list of primitive types you can use. In some scenarios you might want to bind to a strong type and perform automatic conversions to it. A typical use case for this would be a strongly typed identifier that you use in your application.

View model parameters support type conversion using TypeConverter. Your component parameters still needs to be a supported primitive type, however your view model parameter can be strongly typed and will get auto converted. An example for this can be found in the TypedParameter sample.

Dispose

Since ViewModels are being injected through dependency injection in the scope of the component the DI takes care of disposing ViewModels.

Advanced scenarios

Some libraries may force you to use a different base class than MvvmComponentBase. To solve this issue you can create a custom mvvm component using source generators.

Create a partial class and decorate it with the MvvmComponent attribute.

[MvvmComponent]
public abstract partial class CustomComponentBase : UiLibraryComponentBase
{

}

As a reference point see MvvmComponentBase and MvvmComponentBase<T>. Both are generated by a source generator as well.

Examples

Examples for Blazor and Serverside Blazor can be found here.

You will find several projects in there

  • BlazorServersideSample A server for the blazor serverside sample
  • BlazorClientsideSample.Server The server for the blazor clientside sample
  • BlazorClientsideSample.Client The client for the blazor clientside sample

These projects act as wrapper projects for the main functionality that is shared among these examples.

  • BlazorSample.Components The components and pages for the samples
  • BlazorSample.ViewModels The view models for the pages
  • BlazorSample.Domain Domain logic, stuff shared between components and view models

mvvmblazor's People

Contributors

brooklyndev avatar klemmchr avatar kwinkel avatar sschulze1989 avatar twsouthwick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mvvmblazor's Issues

SyncFusion DataGrid not Binding to ObservableCollection of ViewModel

I am trying to bind a ViewModel that wraps an Observable Collection of another ViewModel to a SyncFusion Data Grid.

I am able to enumerate the List based ViewModel outside of the SyncFusion Data Grid using the for each loop when the Observable Collection is of type ViewModel.

The issue I am having is that Sync Fusion defines the Data Grid column through a Field property typically using the nameof method.

This is a small snippet of the ViewModel called OrganizationsViewModel which wraps an ObservableCollection of OrganizationViewModel

image

If I change the ObservableCollection type to anything but the Organization ViewModel it works within the SyncFusion Data Grid.

How canI resolve nameof via ViewModel?

Call to ViewModelBase.StateHasChanged() is not bubbled

When you call StateHasChanged() inside ViewModelBase, it is not forwarded to ComponentBase.

I found ViewModelBase method implementation passing null as PropertyName, but there are no registered handlers for that:

        protected void StateHasChanged()
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(null));
        }

Collections Not Updating After Events

I have a subscription method event tied to collection management and a singleton collection storage object that calls the method. If I have two browser windows open, the event is fired in the window the item was created in but not the other one. I intended to get some effect like ASP.NET Core SignalR sockets realtime but was unable to get that effect. The list will only update if the user makes a change to the data in their own browser.

CascadingParameter availability

Hello,
While looking at your samples, I could find a lot of useful information.
However, I couldn't find anything about CascadingParameter usage.

I tried to pass a string parameter and it is always null.
in view model:

[CascadingParameter]
 public string SomeValue { get; set; }

and in a parent component
<CascadingValue Value="AStringProperty">...</CascadingValue>

Also,
I'm using
in App.Razor which should be available as a cascading a param, as well.

[CascadingParameter]
 public Task<AuthenticationState> AuthenticationStateTask { get; set; }

It is also null in the view model

Could you please advise?

Thank you in advance

Need documentation on the need for sealing the lifecycle methods in MvvmComponentBase<T>

MvvmComponentBase has accessible lifecycle methods. It certainly isn't clear why MvvmComponentBase[T] lifecycle methods are sealed preventing their override in a Blazor component that inherits from that class. I can see why one must call the base implementation of the methods since they are not simple virtuals. If they must remain sealed then documentation is needed as to why, and if they can be opened, then documentation on the need to call the base implementation is also needed.

Blazor Server - No Startup

Question

The startup class doesn't exist when you create a new blazor server project, and .AddMvvm() is not available in program using builder.Services.AddMvvm().

How do I start using this library in this case?

Code sample

No response

Version

0.7.1-preview9

Are you using Blazor WASM or Blazor Server?

Blazor Server

Upgrade to Preview 9

.NET Core 3 Preview 9 has been released and introduces breaking changes. Library needs to be updated to the new version.

MvvmDialogs

Feature description

I developed this framework to provide simple dialogs handling in MVVM.

It currently has implemented for WPF and Avalonia. I believe Blazor support could be added rather easily, but it just takes someone to do it. Would you be interested in implementing MvvmDialogs for Blazor? Seems like the perfect complement for your framework.

Just copy/paste MvvmDialogs.Avalonia and then edit the platform-specific code. If you do, let me know if you run into any problems and I can help with the library code structure and shared code.

Code sample

No response

Disposing ViewModel automatically in MVVMComponentBase

Hi Folks,
I was using this library and wanted to unregister some events inside Dispose method of VIewModel but could not find a best way to call it.
So I did some changes inside MVVMComponentBase to call the Dispose method of the Binding Context if it is disposable.

Should I raise a PR as this might be useful for others as well or do you have any better suggestion?

Below is the PR: #56

Possible issue with two-way binding of a component parameter

I have a component that has a parameter:

[Parameter]
public bool Visible { get; set; }

[Parameter]
public EventCallback<bool> VisibleChanged { get; set; }

The Visible parameter is also defined in the ViewModel and properly passes in.

My issue is that I need that parameter to be a two-way binding:

<Component @bind-Visible="Visible" ... />

Am I setting this up wrong, or is this not possible?

ViewModelBase doesn't implement IAsyncDisposable

Hi. Awesome library! Thanks for making this public so we can learn form and use it. I'm not sure if you want people suggesting issues but I noticed ViewModelBase implements IDisposable but not IAsyncDisposable. I think Blazor didn't used to implement IAsyncDisposable for components but I think it does now... It seems like you might want to add that. Thanks again!

How can an MvvmComponent implement IAsyncDisposable?

Question

I want my MvvmComponent to implement IAsyncDisposable, and do some cleanup in a DisposeAsync() method.

But it appears the source generator automatically adds a DisposeAsync() to MvvmComponents, so I get:

error CS0111: Type 'MyComponent' already defines a member called 'DisposeAsync' with the same parameter types

What's the recommended way around this?

Code sample

No response

Version

6.0.6

Are you using Blazor WASM or Blazor Server?

Blazor WASM

Can the CodeGenerators be bundled with the nuget package?

Sorry, i'm quite a new when it comes to library and source code generators.

I'm just wondering if the CodeGenerators project which helps to generate private property field flagged with NotifyAttribute can be included in the main nuget library?

I can see that it helps to reduce a lot of boilerplate codes, but maybe there are some disadvantages that I'm missing. Please kindly share your view.

ViewModel's Dispose is not being invoked unless page is refreshed

@klemmchr You are right as per the documentation one should not call Dispose but if you look at the example provided by microsoft, the dispose method is called on each new request/refresh of the page but why would one refresh the page to call Dispose? and during my testing as well the Dispose method is called on Page Refresh.
"The debug console shows the following output after each refresh of the Index page:" ~Microsoft

In think there could be two way to solve this problem

  1. via Dispose
  2. Invoking an event say page closed in view model on dispose.

What do you think?

Originally posted by @deveshbahuguna in #55 (comment)

Cascading BindingContext

Is there a way to have cascading BindingContext?
Say we have two components:

class ParentComponent: MvvmComponentBase<ParentViewModel> {
    ChildComponent Child;
}
class ChildComponent: MvvmComponentBase<ChildViewModel> { }
class ParentViewModel: ViewModelBase {
    ChildViewModel Child { get; }
}
class ChildViewModel: ViewModelBase {}

Now I would like to bind the BindingContext of the Child component in the ParentComponent to the Child property of the ParentViewModel instance, which is automatically resolved for the ParentComponent. However it seems the view model is always resolved in the component's constructor via DI, and we don't have a public BindingContext property to override.

Layouts?

Feature description

Would it be possible to support Blazor layouts, such that @Bind() could be used in a file like MainLayout.razor?

Code sample

No response

Cannot use Blazored ILocalStorageService inside ViewModel

Bug description

When injecting an instance of Blazored ILocalStorageService into a ViewModel and inheriting from MvvmComponentBase<>, trying to access a value through the local store will throw the following exception:

- JavaScript interop calls cannot be issued at this time. This is because the component is being statically rendered. When prerendering is enabled, JavaScript interop calls can only be performed during the OnAfterRenderAsync lifecycle method.

This is normally happening when the page is prerendered, however this exception is still being thrown when called inside OnAfterRenderedAsync() and also when prerendering is enabled.

I tried the same approach but injected the ViewModel directly into the component and it was working fine.

Expectation

There should be no Exception when the page is not being rendered or when localStorage is accessed after OnAfterRendered()

Code sample

public class MyViewModel : ViewModelBase
    {
        private readonly ILocalStorageService localStorage;

        public MyViewModel(ILocalStorageService localStorage)
        {
            this.localStorage = localStorage;
        }

        public override async Task OnAfterRenderAsync(bool firstRender)
        {
            if (firstRender)
                await localStorage.GetItemAsStringAsync("test");
        }
    }

Version

6.0.3

Are you using Blazor WASM or Blazor Server?

Blazor Server

What operation system are you working with?

Windows

Community

May I suggest starting a Gitter channel for MvvmBlazor? This is a remarkable library that I feel would benefit immensely from increased community engagement. Currently we're limited to this Issues page on Github, and perhaps Stackoverflow -- not ideal outlets for community discussion. I'd like to share my experiences with this library and see what others are doing.

Using a different base component class

MvvmComponentBase inherits from ComponentBase. What's the best practice if we want to use a different base component class, say OwningComponentBase or AbpComponentBase as we are using the ABP framework, yet still want to keep the functionalities provided by MvvmComponentBase?

Razor page dispose not firing when inheriting from view model

Description

Hi There.

Thanks for this great project.

I found a problem (or is it by design?) where a razor page's dispose method will not fire when inheriting from a view model, even if the view model does not implement dispose itself.

For example; the code below displays a razor component inheriting from a view model but also implementing IDisposable.
As long as the razor component is inheriting from an Mvvm view model, the dispose implementation will never be called here.

@page "/"
@using MvvmBlazor.Components;
@inherits MvvmComponentBase<TestViewModel>
@implements IDisposable

@code {
    void IDisposable.Dispose()
    {
        // NOTE: as long as @inherits is not commented out, this method will not fire.
    }
}

I've put together a sample project demonstrating this behavior here for you.

Code sample

No response

After upgrade to version 6.0.3 scoped dependency injection is not working properly

Bug description

We are getting GetAuthenticationStateAsync was called before SetAuthenticationState after upgrade to version 6.0.3

Our Authentication Service is registred as scoped service and is injected on the Layout.razor page and in ViewModel. We can see, that there are two different instances. With version 2.0.0 it works as expected and the instances are the same

Expectation

Scoped service instances are the same for all injections on current request

Code sample

public class ScopedService { }
// Register service
builder.Services.AddScoped<ScopedService>();
// make a component and the view model
@inherits MvvmBlazor.Components.MvvmComponentBase<MvvmComponentViewModel>
<h1>MvvmComponent injected ScopedService Hash: @BindingContext.GetInjectedServiceHash()</h1>

//---------------------------
    public class MvvmComponentViewModel : ViewModelBase
    {
        private readonly ScopedService _scopedService;

        public MvvmComponentViewModel(ScopedService scopedService)
        {
            _scopedService = scopedService;
        }

        public int GetInjectedServiceHash()
        {
            return _scopedService.GetHashCode();
        }
    }

// inject service on razor page and show the HashCodes
@inject ScopedService _scopedService
<h1>Razor injected ScopedService Hash: @_scopedService.GetHashCode()</h1>
<MvvmComponent/>

Version

6.0.3

Are you using Blazor WASM or Blazor Server?

Balzor Server

What operation system are you working with?

Windows

Unable to Pass Down Parameters

I am unable to pass a parameter down from the page to the ViewModel. The BindingContext is not created until after the page is rendered so I cannot set it in the component constructor.

Switch to CommunityToolkit.Mvvm

Feature description

Right now all the code generators are written from scratch. As version 8 of CommunityToolkit.Mvvm is oficialy released it would be great to use it. We could use NotifyPropertyChangedFor, mesaging, and other goodnes which is going to come in future releases.

Code sample

  1. Necessary change in ViewModelBase:
[INotifyPropertyChanged]
public abstract partial class ViewModelBase
{

and removal of INotifyPropertyChanged stuff as CommunityToolkit.Mvvm does it for us.
2. There is a need to change Set to SetProperty (so it introduces breaking change)
3. [Notify] must be changed to [ObservableProperty]

I created working repo:
https://github.com/alikoli/MvvmBlazor-with-CommunityToolkit.Mvvm

No response

Feature request: "MvvmOwningComponentBase" which inherit from OwningComponentBase

Raising new issue as MvvmOwningComponentBase could be added as a seperate feature

@klemmchr we could have one more class "MvvmOwningComponentBase" which inherit from OwningComponentBase and i don't think this will be an anti pattern as you have already created MvvmComponentBase which derive from Blazor's Component base similarly we could have MvvmOwningComponentBase deriving from owning component base.

Originally posted by @deveshbahuguna in #57 (comment)

Allow custom EqualityComparer on ViewModelBase.Set<T>() function

Feature description

The Set<T>() function does use the EqualityComparer<T>.Default default comparer which is great for most use-cases.
However if custom equality testing is required it means the function cannot be used.
With a simple overload it could be enabled to pass a custom comparer using the IEqualityComparer interface to the Set<T>() function without introducing any breaking changes.

Code sample

No response

Why is the lifetime of scoped view models tied to the component lifetime instead of the request lifetime?

Question

According to the docs, "If you register a view model as scoped it will be tied to the lifetime of the component and disposed when the component is disposed."

I'm sure there's a good explanation for this -- but for me, this design doesn't reconcile with the behavior of scoped dependencies in general, which are tied to the request lifetime.

It sounds like in this case, when a component inherits from MvvmComponentBase<T> , MvvmBlazor disposes the view model when the component is disposed -- where normally (for example, when the component inherits from MvvmComponentBase), the view model would live on.

Am I understanding this correctly? I know there's no way to tie a dependency to the lifetime of a component, so maybe scoped was just the "best fit" for your design?

Code sample

No response

Version

6.0.6

Are you using Blazor WASM or Blazor Server?

Blazor WASM

Guidance on Two-Way Binding on a Model property

Question

Hello,
I am just starting out with blazor and your Mvvm library is already helping me a lot getting on.
I just have a question if you could explain how to best handle two-way bindings on properties that are bound from the model.
For example i have a model and a viewmodel like below.
How would i go best to integrate notification into that view model?

Cheers
Simon

Code sample

public class Model 
{
    public string Name { get; set; }
}

public class ViewModel : ViewModelBase
{
    private Model _model;

    public string Name 
    { 
        get  => _model.Name; 
        set 
        {
            _model.Name = value;
            OnPropertyChanged(nameof(Name));
        }
    }
}

Version

6.0.3

Are you using Blazor WASM or Blazor Server?

Balzor Server

Scope management enhancement

Feature description

Hello,

I am in the process of evaluating the technical solutions for a new and relatively large Blazor/WASM project.
We are going to use MVVM, and on this topic I think that MvvmBlazor could help us save a lot of time and energy.

However the fact that all services within a view are resolved to a scope limited to that view could be an issue for us.
I understand that this behavior might be the best one in the general case, and that there is a workaround using the RootServiceProvider.
But this is an option that we might have to rely on quite a lot, and that would likely make our code much less clear.

I would like to suggest a change that would introduce some kind of "hook" so that the services resolution could be customized:

In the MvvmComponentBase class, the ScopeFactory would be declared as IMvvmServiceScopeFactory instead of IServiceScopeFactory.

public interface IMvvmServiceScopeFactory : IServiceScopeFactory { }

The default implementation for that interface would be:

internal class MvvmServiceScopeFactory : IMvvmServiceScopeFactory
{
    private readonly IServiceScopeFactory serviceScopeFactory;

    public MvvmServiceScopeFactory(IServiceScopeFactory serviceScopeFactory)
    {
        this.serviceScopeFactory = serviceScopeFactory;
    }

    public IServiceScope CreateScope() => serviceScopeFactory.CreateScope();
}

It would be registered in AddMvvm()

serviceCollection.AddSingleton<IMvvmServiceScopeFactory, MvvmServiceScopeFactory>();

The current behavior would be unchanged.

I have actually already tested that solution, and implemented a custom IMvvmServiceScopeFactory in a test project.
That implementation relies on an attribute on the classes and constructors parameters (ViewScopeAttribute) to decide on which scope they should be resolved.

I can send a pull request if you think that this feature would benefit to the project.
There should be many alternative solutions to achieve a similar result, we can also discuss them if you are not convinced by this one.

Regards,

Code sample

No response

Index out of bound exception

Bug description

While working on my application it's a once in a lifetime scenario that I've encountered this exception and I'm unable to figure it out why this error came and how to fix this error.

This is the message that I have received

RefreshCountingFromThread Thread Exception : Index was outside the bounds of the array.: at System.Collections.Generic.Dictionary2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) at MvvmBlazor.Internal.WeakEventListener.WeakEventManager.AddWeakEventListener[T](T source, Action2 handler)
at MvvmBlazor.Internal.Bindings.Binding.AddCollectionBindings()
at MvvmBlazor.Internal.Bindings.Binding.SourceOnPropertyChanged(Object sender, PropertyChangedEventArgs e)
at MvvmBlazor.Internal.WeakEventListener.WeakEventListenerBase`2.HandleEvent(Object sender, TArgs e)
at MvvmBlazor.ViewModel.ViewModelBase.OnPropertyChanged(String propertyName)
at MvvmBlazor.ViewModel.ViewModelBase.Set[T](T& field, T value, String propertyName)
at <ViewModel_Full_Path>.UpdateDetailView()

Expectation

How to not get this exception again as the application is used by many clients and the application is deployed in the field already.

Code sample

public ObservableCollection<DetailDataDTO> DetailsData
{
    get { return detailsData; }
    set { Set(ref detailsData, value); }
}

private ObservableCollection<DetailDataDTO> detailsData;

private void UpdateDetailView()
{
	...
	...
	...
	this.DetailsData = this.DataInventory.GetDetailsData();
	...
	...
	...
}

Version

2.0.0

Are you using Blazor WASM or Blazor Server?

Blazor Server

What operation system are you working with?

Linux

Any guidance on how to use MVVMBlazor with Fluxor for state management

Planning a large LOB ASP.Net Core/BlazorWASM project. Shared state management across components/modules and local data caching is needed.

My initial impression is that MVVM/Fluxor overlap/clash at the UI front.

Fluxor also hooks into the razor components to update the view. Razor components need to inherit FluxorComponent. But the whole redux pattern is great for shared state management across components. Any suggestions on how to use Fluxor with MVVM?

Extend docs and examples for sub viewmodels

There is no sample for sub viewmodels (e.g. in a list scenario) and the documentation is not really covering this part. The fetch data example should be extended to cover that.

Issue in MvvmComponentBase validatebinding

I have a base view model with a property I want to bind on. The following code throws an exception because the declaring type is the base class and the viewmodel is the sub class. Is there a specific reason you have this condition?

if (p.DeclaringType != viewModel.GetType())
throw new BindingException($"Cannot find property {p.Name} in type {viewModel.GetType().FullName}");

Parameters with non-public accessors are not set

Question

Hi,
How can I get AuthenticationState in ViewModel? I'm trying with:

[CascadingParameter] Task AuthenticationState { get; set; }

but it is always null.

Thanks.

Code sample

No response

Version

6.0.6

Are you using Blazor WASM or Blazor Server?

Blazor WASM

MvvmComponentBase does not call AsyncServiceScope.DisposeAsync()

Bug description

When a service used within the scope of the MvvmComponentBase implements IAsyncDisposable, its DisposeAsync() method is not called when the component is disposed.

Expectation

MvvmComponentBase should implement IAsyncDisposable and call _scope.DisposeAsync() from its DisposeAsync() method.

Code sample

public abstract class MvvmComponentBase : ComponentBase, IDisposable

Version

6.0.5

Are you using Blazor WASM or Blazor Server?

Blazor WASM

What operation system are you working with?

Windows

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.