MackySoft.Navigathena.Extensions.DependencyInjection 2.0.0-preview.3

This is a prerelease version of MackySoft.Navigathena.Extensions.DependencyInjection.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package MackySoft.Navigathena.Extensions.DependencyInjection --version 2.0.0-preview.3
                    
NuGet\Install-Package MackySoft.Navigathena.Extensions.DependencyInjection -Version 2.0.0-preview.3
                    
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="MackySoft.Navigathena.Extensions.DependencyInjection" Version="2.0.0-preview.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MackySoft.Navigathena.Extensions.DependencyInjection" Version="2.0.0-preview.3" />
                    
Directory.Packages.props
<PackageReference Include="MackySoft.Navigathena.Extensions.DependencyInjection" />
                    
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 MackySoft.Navigathena.Extensions.DependencyInjection --version 2.0.0-preview.3
                    
#r "nuget: MackySoft.Navigathena.Extensions.DependencyInjection, 2.0.0-preview.3"
                    
#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 MackySoft.Navigathena.Extensions.DependencyInjection@2.0.0-preview.3
                    
#: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=MackySoft.Navigathena.Extensions.DependencyInjection&version=2.0.0-preview.3&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=MackySoft.Navigathena.Extensions.DependencyInjection&version=2.0.0-preview.3&prerelease
                    
Install as a Cake Tool

Install MackySoft.Navigathena.Extensions.DependencyInjection alongside the common runtime. In Unity, restore it with NuGetForUnity alongside the Unity adapter. Add these namespaces in composition code:

using MackySoft.Navigathena;
using MackySoft.Navigathena.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;

Register a screen

Return the result of creation.CreateScope(services => …) from the factory of ScreenDefinition<TRoute>. Register the screen's single lifecycle entry point with services.AddScreenLifecycleHandler<Presenter>(). The container resolves its constructor dependencies through normal DI resolution. A missing handler, multiple handlers, or a mismatched route type causes a configuration error before initialization. Do not register the route in the container. Receive it through the arguments to PrepareAsync and ActivateAsync.

This factory uses the application-defined types from the Unity campaign sample. campaignScene is an Inspector AssetReference; applicationProvider is the application's already-built provider containing CampaignService.

using MackySoft.Navigathena.Samples.Campaign;
using MackySoft.Navigathena.Unity;
using MackySoft.Navigathena.Unity.Addressables;

ScreenDefinition<CampaignMapRoute> screen = new(async (creation, token) =>
{
    CampaignMapView view = await creation.AcquireScreenAsync<CampaignMapView>(
        new AddressablesSceneAcquisition(campaignScene), token);

    return creation.CreateScope(services =>
    {
        services.AddSingleton(view);
        services.ImportService<CampaignService>(applicationProvider);
        services.AddScreenLifecycleHandler<CampaignMapPresenter>();
    });
});

Register screen with the catalog, then create and start the ordinary NavigationHost. The adapter does not create another host. The presenter receives the view and service through its normal constructor. It receives each route only when its lifecycle methods run.

AddSingleton(view) registers an existing object; it does not transfer destruction of the scene object to the container. The scene acquisition still owns that scene. Do not add a second ownership registration for the resolved presenter.

Keep Inspector registration in the scene

If several references live in the loaded scene, put the registration code on an application installer component in that scene. The CampaignMapInstaller example exposes ConfigureServices(IServiceCollection); this is an application method, not a required Navigathena interface.

CampaignMapInstaller installer = await creation.AcquireScreenAsync<CampaignMapInstaller>(
    new AddressablesSceneAcquisition(campaignScene), token);

return creation.CreateScope(services =>
{
    services.ImportService<CampaignService>(applicationProvider);
    installer.ConfigureServices(services);
});

The installer holds serialized references and adds registrations. Navigathena owns the resulting scope's lifetime. For a non-Unity application, omit scene acquisition and register the application's views and dependencies in the same way.

Result screens

For screens that return a result, implement IScreenLifecycleHandler<TRoute, TResult>. Factories registered through ScreenCatalogDefinitionBuilder.Register<TRoute, TResult> receive the same ScreenCreationContext<TRoute, TResult> as ScreenDefinition<TRoute, TResult>, so they can use creation.CreateScope(services => …) in the same way.

For example, register the confirmation presenter with services.AddScreenLifecycleHandler<ConfirmationPresenter>(). The adapter checks its ConfirmationRoute / bool contract when constructing the screen. The caller still uses InvokeAsync, and the presenter still answers through ScreenActivityContext<bool>.Call.

Scope ownership and shutdown

Each screen instance receives independent service registrations, a service provider, and an asynchronously disposable service scope. ImportService<T>(applicationProvider) borrows an existing instance; closing the screen does not dispose of that service. Dispose of the application provider only after the navigation host has shut down successfully.

Microsoft.Extensions.DependencyInjection does not provide nested registration containers through a normal IServiceScope. This adapter creates an independent provider for each screen; it does not copy all registrations from the application provider. Import the shared services the screen needs explicitly. Imports must outlive the screen's use of them.

Reusing a screen instance for another history entry does not rebuild its DI scope. The DI scope participates as one owned unit in the screen lifetime's reverse registration order. Acquire its dependencies before calling CreateScope. After lifecycle termination, later initialization registrations release before the scope; the runtime then awaits asynchronous scope disposal before releasing its earlier dependencies. Use TerminateAsync for final operations that need initialization or preparation resources. See ownership and shutdown.

await host.ShutdownAsync();
await applicationProvider.DisposeAsync();

The second line must not run if host shutdown fails to stop users safely. The application owns its provider and startup/shutdown flow; the screen presenter must not dispose of that provider or its shared services.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2.0.0-preview.5 72 10/23/2026
2.0.0-preview.4 71 10/13/2026
2.0.0-preview.3 104 10/8/2026
2.0.0-preview.2 75 10/7/2026
2.0.0-preview.1 92 9/30/2026