From 12ec7935d3e9d7af949d4768c815bb592f31282f Mon Sep 17 00:00:00 2001 From: Dominik Titl <78549750+morning4coffe-dev@users.noreply.github.com> Date: Tue, 17 Dec 2024 21:48:39 +0100 Subject: [PATCH 1/2] docs: Adjust registration specifics for `ThemeService` --- .../ThemeService/HowTo-UseThemeService.md | 48 ++++++++++++------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/doc/Learn/ThemeService/HowTo-UseThemeService.md b/doc/Learn/ThemeService/HowTo-UseThemeService.md index 5fbfc7e731..789c83735a 100644 --- a/doc/Learn/ThemeService/HowTo-UseThemeService.md +++ b/doc/Learn/ThemeService/HowTo-UseThemeService.md @@ -1,40 +1,29 @@ --- uid: Uno.Extensions.ThemeService.Overview --- - # How to use Theme Service This topic explains how to use the `ThemeService` for runtime theme switching and persisting user theme preferences. -## Step-by-step +## Automatic Registration with IoC -1. **Register ThemeService**: - Add the `ThemeService` to your project's host builder configuration. +> [!NOTE] +> The `ThemeService` is automatically registered when you enable IoC (Dependency Injection) or Extensions UnoFeature in your Uno Platform project. This means you typically *do not* need to explicitly register it using `UseThemeSwitching` unless you are not using IoC. - ```csharp - public partial class App : Application - { - protected override void OnLaunched(LaunchActivatedEventArgs args) - { - var builder = this.CreateBuilder(args) - .Configure(host => host - .UseThemeSwitching() - ); - } - } - ``` +## Step-by-step (Typical Usage with IoC) -2. **Consume ThemeService**: - Inject the ThemeService into your view models or other services where you need to manipulate the theme. +1. **Consume ThemeService**: Inject the `ThemeService` into your view models or other services where you need to manipulate the theme. ```csharp public class SettingsViewModel { private readonly IThemeService _themeService; + public SettingsViewModel(IThemeService themeService) { _themeService = themeService; } + public async Task ToggleThemeAsync() { var currentTheme = _themeService.Theme; @@ -44,6 +33,29 @@ This topic explains how to use the `ThemeService` for runtime theme switching an } ``` +## Step-by-step (Manual Registration without IoC or Advanced Scenarios) + +If you are *not* using IoC, Extensions, or require more control over the registration process, you can manually register the `ThemeService`: + +1. When using the Uno.Sdk, follow this guide on how to add `ThemeService` [UnoFeature](xref:Uno.Features.Uno.Sdk#managing-the-unosdk-version). + +1. **Register ThemeService**: Add the `ThemeService` to your project's host builder configuration using `UseThemeSwitching`. + + ```csharp + public partial class App : Application + { + protected override void OnLaunched(LaunchActivatedEventArgs args) + { + var builder = this.CreateBuilder(args) + .Configure(host => host + .UseThemeSwitching() + ); + } + } + ``` + +1. **Consume ThemeService:** (Same as the IoC usage) Inject the `ThemeService` as shown in the previous example. + ## Source Code [ThemeService Implementation](https://github.com/unoplatform/uno.extensions/blob/51c9c1ef14f686363f946588733faecc5a1863ff/src/Uno.Extensions.Core.UI/Toolkit/ThemeService.cs) From 1f985c667a53850f0727ebfe521e60adfc8738dc Mon Sep 17 00:00:00 2001 From: Dominik Titl <78549750+morning4coffe-dev@users.noreply.github.com> Date: Wed, 18 Dec 2024 23:31:05 +0100 Subject: [PATCH 2/2] chore: Update IoC references to DI --- doc/Learn/ThemeService/HowTo-UseThemeService.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/Learn/ThemeService/HowTo-UseThemeService.md b/doc/Learn/ThemeService/HowTo-UseThemeService.md index 789c83735a..28769b1b92 100644 --- a/doc/Learn/ThemeService/HowTo-UseThemeService.md +++ b/doc/Learn/ThemeService/HowTo-UseThemeService.md @@ -5,12 +5,12 @@ uid: Uno.Extensions.ThemeService.Overview This topic explains how to use the `ThemeService` for runtime theme switching and persisting user theme preferences. -## Automatic Registration with IoC +## Automatic Registration with DI > [!NOTE] -> The `ThemeService` is automatically registered when you enable IoC (Dependency Injection) or Extensions UnoFeature in your Uno Platform project. This means you typically *do not* need to explicitly register it using `UseThemeSwitching` unless you are not using IoC. +> The `ThemeService` is automatically registered when you enable DI (Dependency Injection) or Extensions UnoFeature in your Uno Platform project. This means you typically *do not* need to explicitly register it using `UseThemeSwitching` unless you are not using DI. -## Step-by-step (Typical Usage with IoC) +## Step-by-step (Typical Usage with DI) 1. **Consume ThemeService**: Inject the `ThemeService` into your view models or other services where you need to manipulate the theme. @@ -33,9 +33,9 @@ This topic explains how to use the `ThemeService` for runtime theme switching an } ``` -## Step-by-step (Manual Registration without IoC or Advanced Scenarios) +## Step-by-step (Manual Registration without DI or Advanced Scenarios) -If you are *not* using IoC, Extensions, or require more control over the registration process, you can manually register the `ThemeService`: +If you are *not* using DI, Extensions, or require more control over the registration process, you can manually register the `ThemeService`: 1. When using the Uno.Sdk, follow this guide on how to add `ThemeService` [UnoFeature](xref:Uno.Features.Uno.Sdk#managing-the-unosdk-version). @@ -54,7 +54,7 @@ If you are *not* using IoC, Extensions, or require more control over the registr } ``` -1. **Consume ThemeService:** (Same as the IoC usage) Inject the `ThemeService` as shown in the previous example. +1. **Consume ThemeService:** (Same as the DI usage) Inject the `ThemeService` as shown in the previous example. ## Source Code