Exemple #1
0
        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            //We don't want CodeBrix applications to deal with IContainerRegistry - but this is required for Prism;
            // so using it to call our own RegisterTypes() implementation

            //Note that PlatformConfiguration?.Container may be null during the earliest parts of application startup -
            // see the CodeBrixApplication constructor notes above - so falling back on using the _defaultContainer.

            //Here we will do our CodeBrix internal dependencies registration
            (PlatformConfiguration?.Container ?? _defaultContainer).RegisterSingleton(PlatformConfiguration?.Container ?? _defaultContainer, typeof(ICodeBrixContainer));
            (PlatformConfiguration?.Container ?? _defaultContainer).RegisterSingleton(new XamarinMessagingService(), typeof(IMessagingService));
            (PlatformConfiguration?.Container ?? _defaultContainer).RegisterLazySingleton(() => new UserDialogService(), typeof(IUserDialogService));

            //And then call the inheriting application's RegisterTypes() method
            RegisterTypes(PlatformConfiguration?.Container ?? _defaultContainer);

            //Check to see if a 'NavigationPage' was registered, and register the Xamarin.Forms one if not.
            string name = "NavigationPage";

            if (!CodeBrixContainerExtensions.RegisteredPages.Contains(name))
            {
                Type viewType = typeof(Xamarin.Forms.NavigationPage);
                PageNavigationRegistry.Register(name, viewType);
                CodeBrixContainerExtensions.RegisteredPages.Add(name);
                (PlatformConfiguration?.Container ?? _defaultContainer).Register(viewType, viewType, name);
            }
        }
 /// <summary>
 /// Registers a Page for navigation
 /// </summary>
 /// <param name="container"><see cref="IUnityContainer"/> used to register type for Navigation.</param>
 /// <param name="viewType">The type of Page to register</param>
 /// <param name="name">The unique name to register with the Page</param>
 /// <returns><see cref="IUnityContainer"/></returns>
 public static void RegisterTypeForNavigation(this IContainer container, Type viewType, string name)
 {
     PageNavigationRegistry.Register(name, viewType);
     container.Register(typeof(object),
                        viewType,
                        made: Made.Of(FactoryMethod.ConstructorWithResolvableArguments),
                        serviceKey: name);
 }
Exemple #3
0
        /// <summary>
        /// Registers a Page for navigation.
        /// </summary>
        /// <typeparam name="T">The Type of Page to register</typeparam>
        /// <param name="builder"></param>
        /// <param name="name">The unique name to register with the Page</param>
        public static void RegisterTypeForNavigation <T>(this ContainerBuilder builder, string name) where T : Page
        {
            Type type = typeof(T);

            builder.RegisterType(type).Named <object>(name);

            PageNavigationRegistry.Register(name, type);
        }
 public void Register(string key, Type type)
 {
     if (!_registeredPages.ContainsKey(key))
     {
         _registeredPages.Add(key, type);
         PageNavigationRegistry.Register(key, type);
     }
 }
        /// <summary>
        /// Registers a Page for navigation.
        /// </summary>
        /// <typeparam name="T">The Type of Page to register</typeparam>
        /// <param name="name">The unique name to register with the Page</param>
        public static void RegisterTypeForNavigation <T>(this IUnityContainer container, string name) where T : Page
        {
            Type type = typeof(T);

            container.RegisterType(typeof(object), type, name);

            PageNavigationRegistry.Register(name, type);
        }
        /// <summary>
        /// Registers a Page for navigation.
        /// </summary>
        /// <typeparam name="TView">The Type of Page to register</typeparam>
        /// <param name="container"><see cref="IUnityContainer"/> used to register type for Navigation.</param>
        /// <param name="name">The unique name to register with the Page</param>
        public static IUnityContainer RegisterTypeForNavigation <TView>(this IUnityContainer container, string name) where TView : Page
        {
            Type type = typeof(TView);

            PageNavigationRegistry.Register(name, type);

            return(container.RegisterType(typeof(object), type, name));
        }
        /// <summary>
        /// Registers a Page for navigation.
        /// </summary>
        /// <typeparam name="TView">The Type of Page to register</typeparam>
        /// <param name="name">The unique name to register with the Page</param>
        public static void RegisterTypeForNavigation <TView>(this IKernel kernel, string name) where TView : Page
        {
            Type type = typeof(TView);

            kernel.Bind <object>().To(type).Named(name);

            PageNavigationRegistry.Register(name, type);
        }
Exemple #8
0
 private static void Register(IContainerRegistry container, string key, Type view, Type viewModel)
 {
     if (viewModel != null)
     {
         container.Register(viewModel);
         ViewModelLocationProvider.Register(view.ToString(), viewModel);
     }
     PageNavigationRegistry.Register(key, (view, viewModel));
 }
Exemple #9
0
 public IContainerRegistry Register(string key, Type type)
 {
     if (!_registeredPages.ContainsKey(key))
     {
         _registeredPages.Add(key, type);
         PageNavigationRegistry.Register(key, type);
     }
     return(this);
 }
 public void RegisterForNavigation <TView, TViewModel>(string Namepage = null) where TViewModel : MVVM.ViewModelBase where TView : Page
 {
     if (string.IsNullOrEmpty(Namepage))
     {
         Namepage = typeof(TView).Name;
     }
     _containerBuilder.RegisterType <TViewModel>();
     PageNavigationRegistry.Register(Namepage, typeof(TView), typeof(TViewModel));
 }
        /// <summary>
        /// Registers a Page for navigation.
        /// </summary>
        /// <typeparam name="T">The Type of Page to register</typeparam>
        /// <typeparam name="C">The Class to use as the unique name for the Page</typeparam>
        /// <param name="container"></param>
        public static void RegisterTypeForNavigation <T, C>(this IUnityContainer container)
            where T : Page
            where C : class
        {
            Type   type = typeof(T);
            string name = typeof(C).FullName;

            container.RegisterType(typeof(object), type, name);

            PageNavigationRegistry.Register(name, type);
        }
        /// <summary>
        /// Registers a Page for navigation.
        /// </summary>
        /// <typeparam name="TView">The Type of Page to register</typeparam>
        /// <typeparam name="TViewModel">The BindableBase ViewModel to use as the unique name for the Page</typeparam>
        /// <param name="container"></param>
        public static IUnityContainer RegisterTypeForNavigation <TView, TViewModel>(this IUnityContainer container)
            where TView : Page
            where TViewModel : BindableBase
        {
            Type   type = typeof(TView);
            string name = typeof(TViewModel).FullName;

            PageNavigationRegistry.Register(name, type);

            return(container.RegisterType(typeof(object), type, name));
        }
Exemple #13
0
        /// <summary>
        /// Registers a Page for navigation.
        /// </summary>
        /// <typeparam name="T">The Type of Page to register</typeparam>
        /// <typeparam name="C">The Class to use as the unique name for the Page</typeparam>
        /// <param name="builder"></param>
        public static void RegisterTypeForNavigation <T, C>(this ContainerBuilder builder)
            where T : Page
            where C : class
        {
            Type   type = typeof(T);
            string name = typeof(C).FullName;

            builder.RegisterType(type).Named <object>(name);

            PageNavigationRegistry.Register(name, type);
        }
Exemple #14
0
        /// <summary>
        /// Registers a Page for navigation.
        /// </summary>
        /// <typeparam name="TView">The Type of Page to register</typeparam>
        /// <typeparam name="TViewModel">The BindableBase ViewModel to use as the unique name for the Page</typeparam>
        /// <param name="kernel"></param>
        public static void RegisterTypeForNavigation <TView, TViewModel>(this IKernel kernel)
            where TView : Page
            where TViewModel : BindableBase
        {
            Type   type = typeof(TView);
            string name = typeof(TViewModel).FullName;

            kernel.Bind <object>().To(type).Named(name);

            PageNavigationRegistry.Register(name, type);
        }
        private static void RegisterForNavigationWithViewModel <TViewModel>(this IContainerRegistry containerRegistry, Type viewType, string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                name = viewType.Name;
            }

            ViewModelLocationProvider.Register(viewType.ToString(), typeof(TViewModel));
            containerRegistry.RegisterForNavigation(viewType, name);
            PageNavigationRegistry.Register(viewType.Name, (viewType, typeof(TViewModel)));
        }
Exemple #16
0
        /// <summary>
        /// Registers a Page for navigation.
        /// </summary>
        /// <typeparam name="T">The Type of Page to register</typeparam>
        /// <typeparam name="C">The Class to use as the unique name for the Page</typeparam>
        /// <param name="kernel"></param>
        public static void RegisterTypeForNavigation <T, C>(this IKernel kernel)
            where T : Page
            where C : class
        {
            Type   type = typeof(T);
            string name = typeof(C).FullName;

            kernel.Bind <object>().To(type).Named(name);

            PageNavigationRegistry.Register(name, type);
        }
Exemple #17
0
        public INavigationServiceExtensionsFixture()
        {
            PageNavigationRegistry.ClearRegistrationCache();

            PageNavigationRegistry.Register("NavigationPage", typeof(NavigationPage));
            PageNavigationRegistry.Register("Page1", typeof(NavigationPathPageMock));
            PageNavigationRegistry.Register("Page2", typeof(NavigationPathPageMock2));
            PageNavigationRegistry.Register("Page3", typeof(NavigationPathPageMock3));
            PageNavigationRegistry.Register("Page4", typeof(NavigationPathPageMock4));
            PageNavigationRegistry.Register("TabbedPage1", typeof(NavigationPathTabbedPageMock));
            PageNavigationRegistry.Register("MasterDetailPage", typeof(MasterDetailPage));
        }
Exemple #18
0
        public void GetPageType()
        {
            PageNavigationRegistry.ClearRegistrationCache();

            var name = "MainPage";
            var type = typeof(PageMock);

            PageNavigationRegistry.Register(name, type);

            var infoType = PageNavigationRegistry.GetPageType(name);

            Assert.Equal(type, infoType);
        }
Exemple #19
0
        public void RegisterPageForNavigation()
        {
            PageNavigationRegistry.ClearRegistrationCache();

            var name = "MainPage";
            var type = typeof(PageMock);

            PageNavigationRegistry.Register(name, type);

            var info = PageNavigationRegistry.GetPageNavigationInfo(name);

            Assert.NotNull(info);
        }
Exemple #20
0
        /// <summary>
        /// Registers a Page for navigation
        /// </summary>
        /// <param name="container"><see cref="ICodeBrixContainer"/> used to register type for Navigation.</param>
        /// <param name="viewType">The type of Page to register</param>
        /// <param name="name">The unique name to register with the Page</param>
        public static void RegisterForNavigation(this ICodeBrixContainer container, Type viewType, string name)
        {
            if (viewType == typeof(Xamarin.Forms.NavigationPage) && name == "NavigationPage")
            {
                throw new InvalidOperationException("It is not necessary to register the 'Xamarin.Forms.NavigationPage' type (unless you are "
                                                    + "registering it with a specific ViewFactory) - this type is automatically registered.");
            }

            PageNavigationRegistry.Register(name, viewType);
            RegisteredPages.Add(name);
            //Was: container.Register(typeof(object), viewType, name); //Not sure why it wanted to register types as 'Object'
            container.Register(viewType, viewType, name);
        }
Exemple #21
0
        /// <summary>
        /// Registers a Page for navigation.
        /// </summary>
        /// <typeparam name="T">The Type of Page to register</typeparam>
        /// <typeparam name="C">The Class to use as the unique name for the Page</typeparam>
        /// <param name="container"></param>
        public static void RegisterTypeForNavigation <T, C>(this IContainer container)
            where T : Page
            where C : class
        {
            Type   type = typeof(T);
            string name = typeof(C).FullName;

            var builder = new ContainerBuilder();

            builder.RegisterType <C>().Named <T>(name);
            builder.Update(container);

            PageNavigationRegistry.Register(name, type);
        }
    private void RegisterAllPages()
    {
        var pageBaseTypeInfo = typeof(Page).GetTypeInfo();
        var types            = GetType().GetTypeInfo().Assembly.DefinedTypes;
        var pageTypeInfos    = types
                               .Where(x => x.IsClass && pageBaseTypeInfo.IsAssignableFrom(x));

        foreach (var page in pageTypeInfos)
        {
            // the next two lines do what RegisterTypeForNavigation does
            Container.RegisterType(typeof(object), page.AsType(), page.Name);
            PageNavigationRegistry.Register(page.Name, page.AsType());
        }
    }
Exemple #23
0
        public static IContainerRegistry AutoRegisterMvvmComponents(this IContainerRegistry containerRegistry, Assembly assembly)
        {
            var pageBaseTypeInfo = typeof(Page).GetTypeInfo();
            // get all pages
            var pageTypesInfos = assembly.DefinedTypes.Where(x => x.IsClass && pageBaseTypeInfo.IsAssignableFrom(x));

            foreach (var page in pageTypesInfos)
            {
                var pageName = GetPageName(page.AsType());
                // the next two lines do what  RegisterTypeForNavigation
                containerRegistry.RegisterForNavigation(page.AsType(), pageName);
                PageNavigationRegistry.Register(pageName, page.AsType());
            }

            return(containerRegistry);
        }
        public INavigationServiceExtensionsFixture()
        {
            ContainerLocator.ResetContainer();
            var container = new Mock <IContainerExtension>();

            container.Setup(x => x.CreateScope()).Returns(Mock.Of <IScopedProvider>());
            ContainerLocator.SetContainerExtension(() => container.Object);
            PageNavigationRegistry.ClearRegistrationCache();

            PageNavigationRegistry.Register("NavigationPage", typeof(NavigationPage));
            PageNavigationRegistry.Register("Page1", typeof(NavigationPathPageMock));
            PageNavigationRegistry.Register("Page2", typeof(NavigationPathPageMock2));
            PageNavigationRegistry.Register("Page3", typeof(NavigationPathPageMock3));
            PageNavigationRegistry.Register("Page4", typeof(NavigationPathPageMock4));
            PageNavigationRegistry.Register("TabbedPage1", typeof(NavigationPathTabbedPageMock));
            PageNavigationRegistry.Register("MasterDetailPage", typeof(MasterDetailPage));
        }
Exemple #25
0
        /// <summary>
        /// Registers a Page for navigation, with a function to create the Page during resolution
        /// </summary>
        /// <typeparam name="TView">The Type of Page to register</typeparam>
        /// <param name="container"><see cref="ICodeBrixContainer"/> used to register type for Navigation.</param>
        /// <param name="viewFactory">A function that will create an instance of the view type</param>
        /// <param name="name">The unique name to register with the Page</param>
        public static void RegisterForNavigation <TView>(this ICodeBrixContainer container, Func <TView> viewFactory, string name = null) where TView : Page
        {
            if (viewFactory == null)
            {
                throw new ArgumentNullException(nameof(viewFactory));
            }
            var viewType = typeof(TView);

            if (string.IsNullOrWhiteSpace(name))
            {
                name = viewType.Name;
            }

            PageNavigationRegistry.Register(name, viewType);
            RegisteredPages.Add(name);
            // ReSharper disable once RedundantTypeArgumentsOfMethod
            container.Register <TView>(viewFactory, name);
        }
 /// <summary>
 /// Registers a Page for navigation
 /// </summary>
 /// <param name="containerRegistry"><see cref="IContainerRegistry"/> used to register type for Navigation.</param>
 /// <param name="viewType">The type of Page to register</param>
 /// <param name="name">The unique name to register with the Page</param>
 public static void RegisterForNavigation(this IContainerRegistry containerRegistry, Type viewType, string name)
 {
     PageNavigationRegistry.Register(name, viewType);
     containerRegistry.Register(typeof(object), viewType, name);
 }
Exemple #27
0
 /// <summary>
 /// Registers a Page for navigation
 /// </summary>
 /// <param name="container"><see cref="IKernel"/> used to register type for Navigation.</param>
 /// <param name="viewType">The type of Page to register</param>
 /// <param name="name">The unique name to register with the Page</param>
 public static void RegisterTypeForNavigation(this IKernel container, Type viewType, string name)
 {
     PageNavigationRegistry.Register(name, viewType);
     container.Bind <object>().To(viewType).Named(name);
 }
 /// <summary>
 /// Registers a Page for navigation
 /// </summary>
 /// <param name="builder"><see cref="ContainerBuilder"/> used to register type for Navigation.</param>
 /// <param name="viewType">The type of Page to register</param>
 /// <param name="name">The unique name to register with the Page</param>
 /// <returns><see cref="ContainerBuilder"/></returns>
 public static ContainerBuilder RegisterTypeForNavigation(this ContainerBuilder builder, Type viewType, string name)
 {
     PageNavigationRegistry.Register(name, viewType);
     RegisterTypeIfMissing(builder, viewType, name);
     return(builder);
 }
Exemple #29
0
 /// <summary>
 /// Registers a Page for navigation
 /// </summary>
 /// <param name="container"><see cref="IUnityContainer"/> used to register type for Navigation.</param>
 /// <param name="viewType">The type of Page to register</param>
 /// <param name="name">The unique name to register with the Page</param>
 /// <returns><see cref="IUnityContainer"/></returns>
 public static IUnityContainer RegisterTypeForNavigation(this IUnityContainer container, Type viewType, string name)
 {
     PageNavigationRegistry.Register(name, viewType);
     return(container.RegisterType(typeof(object), viewType, name));
 }
        public static void RegisterForNavigation(this ITinyIoCBuiltIn container, Type viewType, string name)
        {
            PageNavigationRegistry.Register(name, viewType);

            container.Register(typeof(object), viewType, name);
        }