public static IMauiContext MakeScoped(this IMauiContext mauiContext, LayoutInflater?layoutInflater = null, FragmentManager?fragmentManager = null, Android.Content.Context?context = null, bool registerNewNavigationRoot = false) { var scopedContext = new MauiContext(mauiContext.Services); if (layoutInflater != null) { scopedContext.AddWeakSpecific(layoutInflater); } if (fragmentManager != null) { scopedContext.AddWeakSpecific(fragmentManager); } if (context != null) { scopedContext.AddWeakSpecific(context); } if (registerNewNavigationRoot) { if (fragmentManager == null) { throw new InvalidOperationException("If you're creating a new Navigation Root you need to use a new Fragment Manager"); } scopedContext.AddSpecific(new NavigationRootManager(scopedContext)); } return(scopedContext); }
public void AddSpecificInstanceOverridesBase() { var baseObj = new TestThing(); var collection = new MauiServiceCollection(); collection.AddSingleton(baseObj); var services = new MauiFactory(collection); var specificObj = new TestThing(); var context = new MauiContext(services); context.AddSpecific <TestThing>(specificObj); Assert.Same(specificObj, context.Services.GetService <TestThing>()); }
static void DoAdd(MauiContext ctx) { var specificObj = new TestThing(); ctx.AddSpecific <TestThing>(specificObj); }