From a03a75bb3dfd04e7652dd32f5007bd719853d535 Mon Sep 17 00:00:00 2001 From: Yuriy Durov Date: Thu, 23 May 2024 15:11:47 +0400 Subject: [PATCH] Subscribe ComponentStateContainer to ComponentStateHasChanged --- src/BitzArt.Blazor.MVVM/Factory/ViewModelFactory.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/BitzArt.Blazor.MVVM/Factory/ViewModelFactory.cs b/src/BitzArt.Blazor.MVVM/Factory/ViewModelFactory.cs index 4ec321b..4383462 100644 --- a/src/BitzArt.Blazor.MVVM/Factory/ViewModelFactory.cs +++ b/src/BitzArt.Blazor.MVVM/Factory/ViewModelFactory.cs @@ -46,6 +46,12 @@ public ViewModel Create(IServiceProvider serviceProvider, Type viewModelType, Co var viewModel = (ViewModel)serviceProvider.GetRequiredKeyedService(typeof(ViewModel), viewModelMap.RegistrationKey); viewModel.Signature = signature; + viewModel.OnComponentStateChanged += (sender) => + { + viewModel.ComponentStateContainer?.NotifyStateChanged(); + return Task.CompletedTask; + }; + foreach (var injection in viewModelMap.Injections) { if (injection.IsServiceInjection) @@ -60,8 +66,10 @@ public ViewModel Create(IServiceProvider serviceProvider, Type viewModelType, Co var injectedViewModel = Create(serviceProvider, injection.DependencyType, nestedSignature, parent: viewModel, affectedViewModels: affectedViewModels); injection.Property.SetValue(viewModel, injectedViewModel); - viewModel.OnComponentStateContainerWasSet += (container) - => injectedViewModel.ComponentStateContainer = container; + viewModel.OnComponentStateContainerWasSet += (container) => + { + injectedViewModel.ComponentStateContainer = container; + }; } else if (injection.IsParentViewModelInjection)