Lemon.ModuleNavigation 2.1.1-rc

This is a prerelease version of Lemon.ModuleNavigation.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Lemon.ModuleNavigation --version 2.1.1-rc
                    
NuGet\Install-Package Lemon.ModuleNavigation -Version 2.1.1-rc
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Lemon.ModuleNavigation" Version="2.1.1-rc" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Lemon.ModuleNavigation" Version="2.1.1-rc" />
                    
Directory.Packages.props
<PackageReference Include="Lemon.ModuleNavigation" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Lemon.ModuleNavigation --version 2.1.1-rc
                    
#r "nuget: Lemon.ModuleNavigation, 2.1.1-rc"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Lemon.ModuleNavigation@2.1.1-rc
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Lemon.ModuleNavigation&version=2.1.1-rc&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Lemon.ModuleNavigation&version=2.1.1-rc&prerelease
                    
Install as a Cake Tool

Lemon.ModuleNavigation

<p align="center"> <img src="src/lemon-100.png" /> </p>

NuGet

Language


English

Introduction

Lemon.ModuleNavigation

A lightweight module navigation framework built on top of the Microsoft Dependency Injection (MSDI) for AvaloniaUI, WPF and .net-xaml-platforms else. Support native aot (Avaloniaui)

Lemon.ModuleNavigation.AvaloniaUI

Extending Lemon.ModuleNavigation, this package provides handy NavigationContainers specifically designed for AvaloniaUI.

Key Advantages:

  • Lightweight: Minimal performance overhead.
  • Commonly module options are provided:LoadonDemand; Unload; Multi-Instance.
  • Few dependencies: Only relies on Microsoft.Extensions.DependencyInjection.Abstractions.
  • Framework Agnostic: Does not enforce any specific MVVM framework, allowing developers to use the MVVM framework of their choice.
  • Highly Extensible: Easily customizable to suit specific needs.
  • Simple to Use.

ModuleNavigation screenshot:

20241024223837_rec_

ViewNavigation screenshot:

20241024223936_rec_


Usage:

Create module with View and ViewModel
Module.cs
using System;
using Lemon.ModuleNavigation.Avaloniaui;

namespace Lemon.ModuleNavigation.Sample.ModuleAs
{
    public class ModuleA : AvaModule<ViewA, ViewModelA>
    {
        public ModuleA(IServiceProvider serviceProvider) : base(serviceProvider)
        {

        }

        /// <summary>
        /// Specifies whether this module needs to be loaded on demand
        /// Default value is True
        /// </summary>
        public override bool LoadOnDemand => false;

        /// <summary>
        /// Alias of module for displaying usually
        /// Default value is class name of Module
        /// </summary>
        public override string? Alias => base.Alias;

        /// <summary>
        /// Specifies whether this module allow multiple instances
        /// If true,every navigation to this module will generate a new instance.
        /// Default value is false.
        /// </summary>
        public override bool ForceNew => base.ForceNew;

        /// <summary>
        /// Specifies whether this module can be unloaded.
        /// Default value is false.
        /// </summary>
        public override bool CanUnload => base.CanUnload;

        /// <summary>
        /// Initialize
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();
        }
    }
}

View.cs
using Avalonia.Controls;
using Lemon.ModuleNavigation.Abstracts;

namespace Lemon.ModuleNavigation.Sample.ModuleAs;

public partial class ViewA : UserControl, IView
{
    public ViewA()
    {
        InitializeComponent();
    }
}
ViewModel.cs
using Lemon.ModuleNavigation.Abstracts;
using Lemon.ModuleNavigation.Sample.ViewModels;
using System;

namespace Lemon.ModuleNavigation.Sample.ModuleAs
{
    public class ViewModelA :  IViewModel
    {
        public void Dispose()
        {
	        
        }
    }
}

In MainView.axaml or MainWindow.axaml
ContentControl
<ContentControl lm:NavigationExtension.ModuleContainerName="NContentControl" xmlns:lm="https://github.com/NeverMorewd/Lemon.ModuleNavigation" Grid.Column="1" />
TabControl
<TabControl lm:NavigationExtension.ModuleContainerName="NTabControl" xmlns:lm="https://github.com/NeverMorewd/Lemon.ModuleNavigation" Grid.Column="1" >
   <TabControl.ItemTemplate>
    <DataTemplate>
        <StackPanel Orientation="Horizontal" Spacing="2">
            <TextBlock Text="{Binding Alias}" />
             
            <Button lm:NavigationExtension.CanUnload="{Binding CanUnload}"/>
        </StackPanel>
    </DataTemplate>
   </TabControl.ItemTemplate>
   <TabControl.ContentTemplate>
    <DataTemplate>
	<ContentControl Content="{Binding View}" />
    </DataTemplate>
   </TabControl.ContentTemplate>
</NTabContainer>
MainViewModel.cs
public class MainViewModel : ViewModelBase, IServiceAware
{
    private readonly NavigationService _navigationService;
    private readonly IServiceProvider _serviceProvider;
    private readonly IDialogService _dialogService;
    private readonly ILogger _logger;
    public MainViewModel(IEnumerable<IModule> modules,
        IServiceProvider serviceProvider,
        NavigationService navigationService,
        IDialogService dialogService,
        ILogger<MainViewModel> logger)
    {
        _logger = logger;
        _navigationService = navigationService;
        _serviceProvider = serviceProvider;
        _dialogService = dialogService;
        Modules = new ObservableCollection<IModule>(modules);
    }
    /// <summary>
    /// IServiceAware
    /// <summary>
    public IServiceProvider ServiceProvider => _serviceProvider;
    /// <summary>
    /// Navigation is triggered based on the timing of the customization
    /// </summary>
    public void OnSelectedModuleChanged(IModule? selectedModule)
    {
       _navigationService.NavigateTo(selectedModule!);
    }
    /// <summary>
    /// For binding
    /// </summary>
    public ObservableCollection<IModule> Modules
    {
        get;
        set;
    }
}

With generic host. Using Lemon.Hosting.AvaloniaUIDesktop

Program.cs in Lemon.ModuleNavigation.Sample.DesktopHosting
class Program
{
    [STAThread]
    [SupportedOSPlatform("windows")]
    [SupportedOSPlatform("linux")]
    [SupportedOSPlatform("macos")]
    public static void Main(string[] args)
    {
        var hostBuilder = Host.CreateApplicationBuilder();

        // module navigation
        hostBuilder.Services.AddAvaNavigationSupport();
        // modules
        hostBuilder.Services.AddModule<ModuleA>();
        hostBuilder.Services.AddModule<ModuleB>();
        hostBuilder.Services.AddModule<ModuleC>();
        // views
        hostBuilder.Services.AddView<ViewAlpha, ViewAlphaViewModel>(nameof(ViewAlpha));
        hostBuilder.Services.AddView<ViewBeta, ViewBetaViewModel>(nameof(ViewAlpha));

        hostBuilder.Services.AddAvaloniauiDesktopApplication<App>(BuildAvaloniaApp);
        hostBuilder.Services.AddMainWindow<MainWindow, MainViewModel>();
        var appHost = hostBuilder.Build();
        appHost.RunAvaloniauiApplication<MainWindow>(args);
    }

    public static AppBuilder BuildAvaloniaApp(AppBuilder appBuilder)
    {
        return appBuilder
            .UsePlatformDetect()
            .WithInterFont()
            .LogToTrace()
            .UseReactiveUI();
    }
}

Without generic host

AppWithDI.xaml.cs in Lemon.ModuleNavigation.Sample
public partial class AppWithDI : Application
{
    private IServiceProvider? _serviceProvider;
    public override void Initialize()
    {
        AvaloniaXamlLoader.Load(this);
    }

    public override void OnFrameworkInitializationCompleted()
    {
        var services = new ServiceCollection();
        services.AddNavigationContext()
                .AddModule<ModuleA>()
                .AddSingleton<MainWindow>()
                .AddSingleton<MainView>()
                .AddSingleton<MainViewModel>();

        _serviceProvider = services.BuildServiceProvider();

        var viewModel = _serviceProvider.GetRequiredService<MainViewModel>();

        switch (ApplicationLifetime)
        {
            case IClassicDesktopStyleApplicationLifetime desktop:
                var window = _serviceProvider.GetRequiredService<MainWindow>();
                window.DataContext = viewModel;
                desktop.MainWindow = window;
                break;
            case ISingleViewApplicationLifetime singleView:
                var view = _serviceProvider.GetRequiredService<MainView>();
                view.DataContext = viewModel;
                singleView.MainView = view;
                break;
        }
        base.OnFrameworkInitializationCompleted();
    }
}

Lemon.Extensions.ModuleNavigation.Sample.Desktop

A sample desktop application for Lemon.ModuleNavigation and Lemon.ModuleNavigation.AvaloniaUI.

Lemon.Extensions.ModuleNavigation.Sample.DesktopHosting

A sample desktop application for Lemon.ModuleNavigation and Lemon.ModuleNavigation.AvaloniaUI using AvaloniaUI. It introduces Lemon.Hosting.AvaloniaUIDesktop to support .NET Generic Host.

AOT config:

Update .csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    ...
    <PublishAot>true</PublishAot>
    <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
    ...
  </PropertyGroup>

  <PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
	<IsTrimmable>true</IsTrimmable>
	<PublishTrimmed>true</PublishTrimmed>
  </PropertyGroup>

  <ItemGroup>
	<RdXmlFile Include="rd.xml" />
  </ItemGroup>
</Project>

Add rd.xml

<Directives>
	<Application>
		
		<Assembly Name="Lemon.ModuleNavigation.Sample" Dynamic="Required All"/>
		<Assembly Name="Lemon.ModuleNavigation.Avaloniaui" Dynamic="Required All"/>
		<Assembly Name="Lemon.ModuleNavigation" Dynamic="Required All"/>
	</Application>
</Directives>

Lemon.Toolkit

This is a practical application of Lemon.ModuleNavigation. It is a collection of toolkits for clients based on Semi-Avaloniaui, Lemon.Hosting.AvaloniaUIDesktop, and Lemon.ModuleNavigation. As of now, it includes:

  • Module navigation based on NTabContainer
  • Custom HomeModule
  • Custom console log
  • File Inspector (ongoing)
  • File Comparer (ongoing)
  • ...

image


中文

简介

Lemon.ModuleNavigation

Lemon.ModuleNavigation 是一个基于微软依赖注入(MSDI)的轻量级模块导航框架,专为 AvaloniaUI、WPF 和其他 .NET XAML 平台设计。它支持 Native AOT,为 AvaloniaUI 提供高效的导航,性能开销极低。

Lemon.ModuleNavigation.AvaloniaUI

Lemon.ModuleNavigation 的扩展包,专为 AvaloniaUI 提供特定的 NavigationContainers,使得模块导航更加无缝且灵活。

主要优势:

  • 轻量级:最小的性能开销。
  • 依赖少:只依赖 Microsoft.Extensions.DependencyInjection.Abstractions
  • 框架无关:不强制使用任何特定的 MVVM 框架,允许开发者选择自己喜欢的 MVVM 框架。
  • 高度可扩展:可以轻松定制以满足特定需求。
  • 简单易用

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Lemon.ModuleNavigation:

Package Downloads
Lemon.ModuleNavigation.Avaloniaui

Extending Lemon.ModuleNavigation, this package provides NavigationContainers specifically designed for AvaloniaUI.

Lemon.ModuleNavigation.Wpf

Extending Lemon.ModuleNavigation, this package provides NavigationContainers specifically designed for Wpf.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.2.1 189 7/28/2025
2.2.0 260 7/28/2025 2.2.0 is deprecated because it is no longer maintained.
2.1.2-rc 228 4/10/2025
2.1.1-rc 204 4/2/2025
2.1.0-rc 164 3/29/2025
2.0.9-beta 160 2/14/2025
2.0.8-beta 157 2/9/2025
2.0.7-beta 185 12/14/2024
2.0.6-beta 151 12/9/2024
2.0.5-beta 141 11/17/2024
2.0.4-beta 146 11/17/2024 2.0.4-beta is deprecated because it has critical bugs.
2.0.3-beta 182 11/14/2024
2.0.2-beta 151 11/13/2024
2.0.1-beta 154 11/12/2024
2.0.0-beta 160 11/10/2024
1.0.1 255 10/15/2024
1.0.0 208 10/11/2024