Expose ScopedApplicationShell

This commit is contained in:
2024-08-22 15:27:36 +02:00
parent 98b189e595
commit ef8bf209bc
4 changed files with 16 additions and 6 deletions
@@ -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();
+11 -2
View File
@@ -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();
}
}
@@ -56,7 +56,8 @@ public static class MauiAppBuilderExtensions
public static MauiAppBuilder WithNavigation(this MauiAppBuilder appBuilder)
{
appBuilder.ThrowIfNull();
appBuilder.Services.AddScoped<Shell, ScopedApplicationShell>(sp => new ScopedApplicationShell(sp));
appBuilder.Services.AddScoped<ScopedApplicationShell, ScopedApplicationShell>(sp => new ScopedApplicationShell(sp));
appBuilder.Services.AddScoped<Shell, ScopedApplicationShell>(sp => sp.GetRequiredService<ScopedApplicationShell>());
appBuilder.Services.AddScoped<INavigationService, NavigationService>();
return appBuilder;
@@ -20,7 +20,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
<Version>0.2.1</Version>
<Version>0.2.3</Version>
<Authors>Alexandru Macocian</Authors>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>