public async Task <IControl> BuildAsync(object viewModel)
        {
            string id = null;

            if (viewModel is ITabViewModel dock)
            {
                id = dock.Id;
                if (dock.RequiresViewRefresh)
                {
                    Logger.Verbose($"Tab requires refresh '{id}'");
                    views.Remove(id);
                    dock.RequiresViewRefresh = false;
                }
            }
            else if (viewModel is EditorViewModel)
            {
                id = "root";
            }
            else
            {
                throw new NotSupportedException();
            }

            Logger.Debug($"Building view for object '{id}'.");

            ViewContainer container;

            if (!views.TryGetValue(id, out container))
            {
                await AvaloniaUIThread.InvokeAsync(() =>
                {
                    container = new ViewContainer(new ContentControl(), CreateView, Cleanup);
                });

                views.Add(id, container);
            }

            var context = new ViewUpdateContext
            {
                CommandDispatcher = Services.GetSafeServiceAs <ICommandDispatcher>(),
                ViewModel         = viewModel,
                View = ViewRegistry.GetView(viewModel, Services),
            };

            await container.Update(context);

            return(container.Container);
        }
 /// <summary>
 /// On the UI thread, creates a view from the <see cref="ViewFactory"/>, updates UI, calls <see cref="Cleanup"/>.
 /// </summary>
 /// <param name="context">Context passed to user methods</param>
 public async Task Update(object context)
 {
     // creating view has to happen on the UI thread because some data structures
     // e.g. Grid.ColumnsDefinitions require that
     await AvaloniaUIThread.InvokeAsync(() => CreateAndUpdateView(context));
 }