Skip to content

Commit

Permalink
Merge pull request #2326 from unoplatform/dev/erli/2321-HowToExtensio…
Browse files Browse the repository at this point in the history
…nsExistingApp

docs: Add guide to Install Extensions in existing app
  • Loading branch information
nickrandolph committed Jun 24, 2024
2 parents 80422de + e4ddfae commit 860cefe
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
45 changes: 42 additions & 3 deletions doc/GettingStarted.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
---
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 Uno.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

### [Wizard](#tab/wizard)

#### Create an Uno Platform app with Wizard

* Create a new C# solution using the **Uno Platform App** template, from Visual Studio's **Start Page**, then click the **Next** button
Expand All @@ -37,6 +39,8 @@ This tutorial will walk you through how to create an Uno application with Uno.Ex
* A banner at the top of the editor may ask to reload projects, click **Reload projects**:
![Visual Studio - A banner indicating to reload projects](./Learn/images/vs2022-project-reload.png)

### [Command Line](#tab/cli)

#### Create an Uno Platform app with the CLI

The `dotnet` templates included in the `Uno.Templates` package are used to easily create new projects that already reference the Uno.Extensions.
Expand All @@ -59,6 +63,8 @@ The `dotnet` templates included in the `Uno.Templates` package are used to easil

`.\MyProjectName\MyProjectName.sln`

---

### 2. Exploring the Solution

The generated solution will contain *MyProjectName* for application logic, including constructs like ViewModels and services, along with the pages, controls, and other views constituting the UI of the application.
Expand All @@ -72,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;
```
8 changes: 6 additions & 2 deletions doc/Learn/Hosting/HostingOverview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<UnoFeatures>` 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

Expand Down Expand Up @@ -78,6 +81,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
});

Host = appBuilder.Build();
}
...
```

Expand Down
13 changes: 11 additions & 2 deletions doc/Learn/Hosting/HowTo-HostingSetup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 `<UnoFeatures>` property in the Class Library (.csproj) file. If you already have `Extensions` in `<UnoFeatures>`, then `Hosting` is already installed, as its dependencies are included with the `Extensions` feature.

```diff
<UnoFeatures>
Material;
+ Hosting;
Toolkit;
MVUX;
</UnoFeatures>
```

### 2. Create and Configure IApplicationBuilder

Expand Down
Binary file modified doc/Learn/images/newproject1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 860cefe

Please sign in to comment.