refactor: page factory and less mvvm-breaking

This commit is contained in:
estrogen elf
2025-06-23 09:37:30 -05:00
parent c78f75a332
commit 471559d987
12 changed files with 118 additions and 90 deletions
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Needlework.Net.ViewModels.Pages
{
public class PageFactory
{
private readonly IEnumerable<PageBase> _pages;
public PageFactory(IEnumerable<PageBase> pages)
{
_pages = pages;
}
public PageBase GetPage<T>() where T : PageBase
{
var page = _pages.Where(page => typeof(T) == page.GetType())
.FirstOrDefault() ?? throw new NotSupportedException(typeof(T).FullName);
Task.Run(page.InitializeAsync);
return page;
}
}
}