From c90d92dadf31d6699203524f55f1bbb7fd15a841 Mon Sep 17 00:00:00 2001 From: eriklimakc Date: Thu, 6 Jun 2024 16:32:04 +0100 Subject: [PATCH] docs: Add guide to Install Extensions in existing app --- doc/GettingStarted.md | 39 +++++++++++++++++++++++-- doc/Learn/Hosting/HostingOverview.md | 8 +++-- doc/Learn/Hosting/HowTo-HostingSetup.md | 13 +++++++-- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/doc/GettingStarted.md b/doc/GettingStarted.md index 30573ddf41..75fc7066b0 100644 --- a/doc/GettingStarted.md +++ b/doc/GettingStarted.md @@ -1,14 +1,14 @@ --- uid: Uno.Extensions.HowToGettingStarted --- -# How-To: Creating an application with Uno.Extensions +# How-To: Getting Started -This tutorial will walk you through how to create an Uno application with Uno.Extensions using the Wizard and CLI. +This tutorial will walk you through how to create an Uno application with Uno.Extensions using the Wizard and CLI and how to install Extensions to an existing Uno application. > [!NOTE] > Make sure to setup your environment first by [following our instructions](xref:Uno.GetStarted.vs2022). -## Step-by-steps +## Creating a new application ### 1. Creating the app @@ -78,3 +78,36 @@ The generated solution will contain *MyProjectName* for application logic, inclu ![A screenshot of the generated targets](./Learn/images/GeneratedTargets-min.png) * Click the "play" button, or press F5 to start debugging. The project will be compiled and deployed based on the target platform. For more detailed instructions specific to each platform, refer to the [Debug the App](xref:Uno.GettingStarted.CreateAnApp.VS2022#debug-the-app) documentation. + +## Installing Extensions in an existing project + +To get started with Extensions in your project, follow these steps: + +### Step 1: Add Hosting to Your Project + +Hosting is the foundation for using Extensions. Begin by adding Hosting to your project. Refer to the detailed instructions in the [Hosting Setup Documentation](xref:Uno.Extensions.Hosting.HowToHostingSetup). + +### Step 2: Configure the OnLaunched Method + +After setting up Hosting, adjust the `OnLaunched` method in `App.xaml.cs` to initialize the Extensions features. Ensure you have added the necessary [Uno Platform Features](xref:Uno.Features.Uno.Sdk#uno-platform-features). + +Update the `Configure` method as shown below: + +```csharp +var builder = this.CreateBuilder(args) + .Configure(host => host + // Configure the host builder + .UseConfiguration(...) + .UseLocalization() + .UseSerialization(...) + .UseHttp(...) + ); +``` + +### Step 3: Use the Builder to Create the Main Window + +Finally, instead of directly creating an instance of a `Window` using `MainWindow = new Window()`, use the `builder` to set up the main window: + +```csharp +MainWindow = builder.Window; +``` diff --git a/doc/Learn/Hosting/HostingOverview.md b/doc/Learn/Hosting/HostingOverview.md index b6f4cfd337..5c85ae7592 100644 --- a/doc/Learn/Hosting/HostingOverview.md +++ b/doc/Learn/Hosting/HostingOverview.md @@ -3,9 +3,12 @@ uid: Uno.Extensions.Hosting.Overview --- # Hosting -`Uno.Extensions.Hosting` provides an implementation of the abstraction for building applications which support initialization of dependencies, establishing different environment types, and the full breadth of extensible features offered by Uno.Extensions. +`Hosting` provides an implementation of the abstraction for building applications which support initialization of dependencies, establishing different environment types, and the full breadth of extensible features offered by Uno.Extensions. -Hosting is delivered as a NuGet package [Uno.Extensions.Hosting.WinUI](https://www.nuget.org/packages/Uno.Extensions.Hosting.WinUI). +Hosting is provided as an Uno Feature. To enable `Hosting` support in your application, add `Hosting` to the `` property in the Class Library (.csproj) file. For more information about `UnoFeatures` refer to our [Using the Uno.Sdk](xref:Uno.Features.Uno.Sdk) docs. + +> [!IMPORTANT] +> This walkthrough assumes you created your app using the Single Project template. If you used a different template, please refer to our [Migrating Projects to Single Project](xref:Uno.Development.MigratingToSingleProject) documentation. ## Building a Hosted Application @@ -78,6 +81,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e) }); Host = appBuilder.Build(); +} ... ``` diff --git a/doc/Learn/Hosting/HowTo-HostingSetup.md b/doc/Learn/Hosting/HowTo-HostingSetup.md index 9a84493735..eee98b1503 100644 --- a/doc/Learn/Hosting/HowTo-HostingSetup.md +++ b/doc/Learn/Hosting/HowTo-HostingSetup.md @@ -3,7 +3,7 @@ uid: Uno.Extensions.Hosting.HowToHostingSetup --- # How-To: Get Started with Hosting -`Uno.Extensions.Hosting` can be used to register services that will be accessible throughout the application via dependency injection (DI). This tutorial will walk you through the critical steps needed to leverage hosting in your application. +`Hosting` can be used to register services that will be accessible throughout the application via dependency injection (DI). This tutorial will walk you through the critical steps needed to leverage hosting in your application. > [!WARNING] > The steps outlined here are unnecessary if you used the new project wizard template to create your solution. Otherwise, it is recommended that you follow the [Creating an application with Uno.Extensions article](xref:Uno.Extensions.HowToGettingStarted) for creating an application from the template. @@ -12,7 +12,16 @@ uid: Uno.Extensions.Hosting.HowToHostingSetup ### 1. Installation -* Install the [Uno.Extensions.Hosting.WinUI](https://www.nuget.org/packages/Uno.Extensions.Hosting.WinUI) package from NuGet. +* Add `Hosting` to the `` property in the Class Library (.csproj) file. If you already have `Extensions` in ``, then `Hosting` is already installed, as its dependencies are included with the `Extensions` feature. + + ```diff + + Material; + + Hosting; + Toolkit; + MVUX; + + ``` ### 2. Create and Configure IApplicationBuilder