Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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>());
        }
Esempio n. 3
0
            static void DoAdd(MauiContext ctx)
            {
                var specificObj = new TestThing();

                ctx.AddSpecific <TestThing>(specificObj);
            }