protected override void OnInit() { // Update type information before rendering UpdateTypeInformation(); // Create ViewModel if not yet created. if (ViewModelManager == null || ViewModelManager.Current == null) { Debug.WriteLine("Creating new view model for type " + ViewModelType); ViewModelManager = new ViewModelManager(ViewModelRepository.CreateViewModel(ViewModelType)); } _isInitialized = true; }
#pragma warning restore CS0169 public void ConfigureServices(IServiceCollection services) { services.AddSingleton <ISessionStateManager, SessionStateManager>(); services.AddSingleton <ICommandFactory, CommandFactory>(); services.AddSingleton <IViewModelRepository, ViewModelRepository>(); services.AddSingleton <IViewRepository, ViewRepository>(); services.AddSingleton <IViewTypeSelector, ViewTypeSelector>(); services.AddTransient <IStateStorage, CookieStorage>(); // Force viewmodel to load assembly to search var vmAssembly = "JAICT.Blazor.Recipes.UI.Client.ViewModels, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"; foreach (var viewModelType in ViewModelRepository.GetViewModelTypes(new[] { vmAssembly })) { services.AddTransient(viewModelType); } }
private static void AttachViewModel(FrameworkElement element, string vmContractName, bool isShared) { if (element == null) { throw new ArgumentException("Invalid element for attached property"); } try { if (!String.IsNullOrEmpty(vmContractName)) { ViewModelRepository.AttachViewModelToView(vmContractName, element, isShared); } } catch (Exception ex) { Debug.WriteLine("Error while resolving ViewModel. " + ex); } }