Skip to content

Commit

Permalink
Shell pages don't need registering.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbritch committed Nov 6, 2024
1 parent e375b22 commit 8e30b5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/fundamentals/dependency-injection.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ When registering dependencies, you need to register all dependencies including i
> [!TIP]
> A dependency injection container is ideal for creating view-model instances. If a view-model has dependencies, it will manage the creation and injection of any required services. Just ensure that you register your view-models and any dependencies that they may have in the `CreateMauiApp` method in the `MauiProgram` class.
::: moniker range=">=net-maui-9.0"

In a Shell app, you don't need to register your pages with the dependency injection container unless you want to influence the lifetime of the page relative to the container with the [`AddSingleton`](xref:Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton%2A), [`AddTransient`](xref:Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddTransient%2A), or [`AddScoped`](xref:Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddScoped%2A) methods. For more information, see [Dependency lifetime](#dependency-lifetime).

::: moniker-end

### Dependency lifetime

Depending on the needs of your app, you may need to register dependencies with different lifetimes. The following table lists the main methods you can use to register dependencies, and their registration lifetimes:
Expand Down
6 changes: 5 additions & 1 deletion docs/whats-new/dotnet-9.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: What's new in .NET MAUI for .NET 9
description: Learn about the new features introduced in .NET MAUI for .NET 9.
ms.date: 10/24/2024
ms.date: 11/06/2024
---

# What's new in .NET MAUI for .NET 9
Expand Down Expand Up @@ -289,6 +289,10 @@ In .NET MAUI 8, compiled bindings are disabled for any XAML binding expressions

By default, .NET MAUI 9 produces build warnings for bindings that don't use compiled bindings. For more information about XAML compiled bindings warnings, see [XAML compiled bindings warnings](~/fundamentals/data-binding/compiled-bindings.md?view=net-maui-9.0&preserve-view=true#xaml-compiled-bindings-warnings).

## Dependency injection

In a Shell app, you no longer need to register your pages with the dependency injection container unless you want to influence the lifetime of the page relative to the container with the [`AddSingleton`](xref:Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton%2A), [`AddTransient`](xref:Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddTransient%2A), or [`AddScoped`](xref:Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddScoped%2A) methods. For more information about these methods, see [Dependency lifetime](~/fundamentals/dependency-injection.md#dependency-lifetime).

## Handler disconnection

When implementing a custom control using handlers, every platform handler implementation is required to implement the <xref:Microsoft.Maui.IElementHandler.DisconnectHandler> method, to perform any native view cleanup such as unsubscribing from events. However, prior to .NET MAUI 9, the <xref:Microsoft.Maui.IElementHandler.DisconnectHandler> implementation is intentionally not invoked by .NET MAUI. Instead, you'd have to invoke it yourself when choosing to cleanup a control, such as when navigating backwards in an app.
Expand Down

0 comments on commit 8e30b5b

Please sign in to comment.