mirror of
https://github.com/AlexMacocian/Net.Maui.Extensions.git
synced 2026-07-15 14:59:31 +00:00
Expose ScopedApplicationShell
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user