Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/Core/src/MauiContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ namespace Microsoft.Maui
public class MauiContext : IMauiContext
{
readonly WrappedServiceProvider _services;
readonly Lazy<IMauiHandlersFactory> _handlers;

#if ANDROID
readonly Lazy<Android.Content.Context?> _context;

public Android.Content.Context? Context => _context.Value;

#if __ANDROID__
public MauiContext(IServiceProvider services, Android.Content.Context context)
: this(services)
{
Expand All @@ -19,17 +24,15 @@ public MauiContext(IServiceProvider services, Android.Content.Context context)
public MauiContext(IServiceProvider services)
{
_services = new WrappedServiceProvider(services ?? throw new ArgumentNullException(nameof(services)));
_handlers = new Lazy<IMauiHandlersFactory>(() => _services.GetRequiredService<IMauiHandlersFactory>());
#if ANDROID
_context = new Lazy<Android.Content.Context?>(() => _services.GetService<Android.Content.Context>());
#endif
}

public IServiceProvider Services => _services;

public IMauiHandlersFactory Handlers =>
Services.GetRequiredService<IMauiHandlersFactory>();

#if __ANDROID__
public Android.Content.Context? Context =>
Services.GetService<Android.Content.Context>();
#endif
public IMauiHandlersFactory Handlers => _handlers.Value;

internal void AddSpecific<TService>(TService instance)
where TService : class
Expand Down