ShellInject 9.0.1
dotnet add package ShellInject --version 9.0.1
NuGet\Install-Package ShellInject -Version 9.0.1
<PackageReference Include="ShellInject" Version="9.0.1" />
<PackageVersion Include="ShellInject" Version="9.0.1" />
<PackageReference Include="ShellInject" />
paket add ShellInject --version 9.0.1
#r "nuget: ShellInject, 9.0.1"
#:package ShellInject@9.0.1
#addin nuget:?package=ShellInject&version=9.0.1
#tool nuget:?package=ShellInject&version=9.0.1
ShellInject
ShellInject simplifies navigation and data transfer between ViewModels in .NET MAUI applications by leveraging the power of Shell Navigation combined with robust Dependency Injection. This package eliminates the need to manually register routes or ViewModels in your services, as ShellInject automatically handles route registration and ViewModel bindings for you.
With a single-line setup, ShellInject enhances maintainability and reduces boilerplate code, setting the BindingContext dynamically based on the ViewModelType property defined in XAML. This enables effortless parameter passing, lifecycle management, and seamless ViewModel interactions, making it ideal for applications with complex navigation flows or multi-page structures.
Setup
MauiProgram.cs
To enable ShellInject and integrate its features into your app, add the .UseShellInject()
line of code in your MauiProgram.cs
:
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.RegisterServices()
.UseShellInject();
return builder.Build();
Usage
ViewModels
Ensure your ViewModels inherit from ShellInjectViewModel
to handle navigation events and parameter passing. You can override the following methods based on your needs:
OnAppearedAsync()
– Triggered everytime a page is navigated to.InitializedAsync()
- Invoked once when the viewmodel is loaded for the first time.DataReceivedAsync(object? parameter)
– Triggered when data is passed to the ViewModel (forward navigation).ReverseDataReceivedAsync(object? parameter)
– Handles data returned when navigating back from a page (back navigation).
ShellInject now handles the following methods out of the box. Just override them in your viewmodel.
OnAppearing()
– Called when the page is about to appear.OnDisappearing()
– Called when the page is about to disappear.
ContentPage
In your ContentPage.xaml
file, specify the ViewModel to bind by setting the ViewModelType
property. This ensures that the correct ViewModel is injected and bound to the page:
xmlns:ez="clr-namespace:ShellInject;assembly=ShellInject"
ez:ShellInjectPageExtensions.ViewModelType="{x:Type vm:MainViewModel}"
Navigation
ShellInject provides extension methods to simplify navigation between pages and passing parameters between ViewModels:
Example:
await Shell.Current.PushAsync<DetailsPage>(new { id = 123, name = "John" });
Available navigation methods:
Pushing:
PushAsync<TPageType>(someData)
PushMultiStackAsync(pageTypes, someData)
Modals:
PushModalWithNavigationAsync(contentPage, someData)
PushModalAsync<TPageType>(someData)
Popping:
PopAsync(someData)
PopModalStackAsync(someData)
PopToAsync<TPageType>(someData)
PopToRootAsync(someData)
Popups:
ShowPopupAsync<TPopup>(someData)
DismissPopupAsync<TPopup>(someData)
Replacing Root Pages in a Flyout Menu:
ReplaceAsync<TPageType>(someData)
Changing Tabs:
ChangeTabAsync(tabIndex, someData)
Helper methods:
This method looks for the specified Page on the stack and sends the data using the ReverseDataReceivedAsync method.
SendDataToPageAsync<TPageType>(someData)
Note: this method is now Deprecated.
ServiceProvider
Retrieving services manually, you can use the following:
Injector.GetRequiredService<ISampleService>();
Injector.GetService<ISampleService>();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-android35.0 is compatible. net9.0-browser was computed. net9.0-ios was computed. net9.0-ios18.0 is compatible. net9.0-maccatalyst was computed. net9.0-maccatalyst18.0 is compatible. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- No dependencies.
-
net9.0-android35.0
- No dependencies.
-
net9.0-ios18.0
- No dependencies.
-
net9.0-maccatalyst18.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
9.0.1 | 0 | 8/8/2025 |
3.1.7 | 99 | 6/21/2025 |
3.1.6 | 381 | 4/8/2025 |
3.1.5 | 160 | 4/3/2025 |
3.1.4 | 150 | 3/20/2025 |
3.1.3 | 78 | 3/15/2025 |
3.1.2 | 136 | 2/13/2025 |
3.1.1 | 127 | 2/5/2025 |
3.1.0 | 128 | 2/3/2025 |
3.0.11 | 122 | 1/31/2025 |
3.0.10 | 104 | 1/29/2025 |
3.0.9 | 100 | 1/27/2025 |
3.0.8 | 96 | 1/27/2025 |
3.0.7 | 107 | 1/27/2025 |
3.0.6 | 101 | 1/23/2025 |
3.0.5 | 109 | 1/17/2025 |
3.0.4 | 430 | 11/1/2024 |
3.0.3 | 161 | 10/23/2024 |
3.0.2 | 105 | 10/22/2024 |
3.0.1 | 113 | 10/21/2024 |
3.0.0 | 117 | 10/20/2024 |
• Upgraded to .NET 9 support
• Fixed issues with showing popups via ShowPopupAsync
• Fixed ReplaceAsync to reliably trigger DataReceivedAsync
• Fixed ChangeTabAsync to support TabbedPages correctly
• Resolved dependency issues when installing the package
• General bug fixes and improvements