diff --git a/Net.Maui.Extensions/ControlFlow/ScopedApplicationShell.cs b/Net.Maui.Extensions/ControlFlow/ScopedApplicationShell.cs index a8d1c6a..42b5ee0 100644 --- a/Net.Maui.Extensions/ControlFlow/ScopedApplicationShell.cs +++ b/Net.Maui.Extensions/ControlFlow/ScopedApplicationShell.cs @@ -2,11 +2,11 @@ namespace Net.Maui.Extensions.ControlFlow; -internal class ScopedApplicationShell : Shell +public class ScopedApplicationShell : Shell { private readonly IServiceProvider serviceProvider; - public ScopedApplicationShell( + internal ScopedApplicationShell( IServiceProvider serviceProvider) { this.serviceProvider = serviceProvider.ThrowIfNull(); diff --git a/Net.Maui.Extensions/ExtendedApplication.cs b/Net.Maui.Extensions/ExtendedApplication.cs index 17f8ac3..4dc8def 100644 --- a/Net.Maui.Extensions/ExtendedApplication.cs +++ b/Net.Maui.Extensions/ExtendedApplication.cs @@ -1,11 +1,20 @@ -using System.Core.Extensions; +using Net.Maui.Extensions.ControlFlow; +using System.Core.Extensions; namespace Net.Maui.Extensions; public abstract class ExtendedApplication : Application { - public ExtendedApplication(Shell shell) + public ScopedApplicationShell ScopedShell { get; } + + public ExtendedApplication(ScopedApplicationShell shell) { + if (shell is not ScopedApplicationShell) + { + throw new InvalidOperationException($"Shell is not of type {typeof(ScopedApplicationShell).Name}"); + } + this.MainPage = shell.ThrowIfNull(); + this.ScopedShell = shell.ThrowIfNull(); } } diff --git a/Net.Maui.Extensions/MauiAppBuilderExtensions.cs b/Net.Maui.Extensions/MauiAppBuilderExtensions.cs index 0b4973f..d8a9495 100644 --- a/Net.Maui.Extensions/MauiAppBuilderExtensions.cs +++ b/Net.Maui.Extensions/MauiAppBuilderExtensions.cs @@ -56,7 +56,8 @@ public static class MauiAppBuilderExtensions public static MauiAppBuilder WithNavigation(this MauiAppBuilder appBuilder) { appBuilder.ThrowIfNull(); - appBuilder.Services.AddScoped(sp => new ScopedApplicationShell(sp)); + appBuilder.Services.AddScoped(sp => new ScopedApplicationShell(sp)); + appBuilder.Services.AddScoped(sp => sp.GetRequiredService()); appBuilder.Services.AddScoped(); return appBuilder; diff --git a/Net.Maui.Extensions/Net.Maui.Extensions.csproj b/Net.Maui.Extensions/Net.Maui.Extensions.csproj index 8234a23..7f2ec1d 100644 --- a/Net.Maui.Extensions/Net.Maui.Extensions.csproj +++ b/Net.Maui.Extensions/Net.Maui.Extensions.csproj @@ -20,7 +20,7 @@ enable enable true - 0.2.1 + 0.2.3 Alexandru Macocian LICENSE true