private readonly ThemeState _state;public MyClass(ThemeState state = null){ _state = state;}
services.AddSingleton<ThemeState>(); Resources.Add("services", services.BuildServiceProvider());
public class ThemeState{ public CssBuilder ThemeCSS { get; set; } public event Action OnChange; public ThemeState() { ThemeCSS = CssBuilder.FromFile(ThemePath, ":root"); } public static readonly string WWWRootPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "wwwroot"); public static readonly string ThemePath = Path.Combine(WWWRootPath, "css", "theme.css"); public void ApplyTheme(CssBuilder css) { ThemeCSS = css; OnChange?.Invoke(); } public void UpdateTheme(string property, string value) { ThemeCSS.SetProperty(property, value); OnChange?.Invoke(); }}