예제 #1
0
        private object GetBindingContext(Type viewType)
        {
            var viewModelType = _viewsByType[viewType];

            ConstructorInfo constructor = null;

            var parameters = new object[] { };

            constructor = viewModelType.Type.GetTypeInfo()
                          .DeclaredConstructors
                          .FirstOrDefault(c => !c.GetParameters().Any());

            if (constructor == null)
            {
                constructor = viewModelType.Type.GetTypeInfo()
                              .DeclaredConstructors.First();

                var parameterList = new List <object>();

                foreach (var param in constructor.GetParameters())
                {
                    parameterList.Add(_injection.Get(param.ParameterType));
                }

                parameters = parameterList.ToArray();
            }

            if (constructor == null)
            {
                throw new InvalidOperationException(
                          $"No suitable constructor found for ViewModel {viewModelType.ToString()}");
            }

            return(constructor.Invoke(parameters));
        }
예제 #2
0
        public App(PlatformInitializer i_PlatformInitializer)
        {
            InitializeComponent();
            Exrin.IOC.LightInjectProvider.Init(i_PlatformInitializer, new FormsInitializer());
            IInjectionProxy    injectionProxy    = Bootstrapper.Instance.Init();
            INavigationService navigationService = injectionProxy.Get <INavigationService>();

            navigationService.Navigate(new StackOptions()
            {
                StackChoice = eStack.Authentication
            });
        }
예제 #3
0
        protected virtual void StartInsights(IList <IInsightsProvider> providers)
        {
            var processor = _injection.Get <IInsightsProcessor>();

            if (providers != null)
            {
                foreach (var provider in providers)
                {
                    processor.RegisterService(provider.ToString(), provider);
                }
            }

            _injection.Get <IInsightsProcessor>().Start();
        }
예제 #4
0
        public void RegisterViewContainer <T>() where T : class, IViewContainer
        {
            _injection.Register <T>(InstanceType.SingleInstance);

            var            viewContainer = _injection.Get <T>();
            IList <IStack> stacks        = new List <IStack>();

            // Load list of stacks depending on ViewContainer
            if (viewContainer as ISingleContainer != null)
            {
                stacks.Add(((ISingleContainer)viewContainer).Stack);
            }
            else if (viewContainer as IMasterDetailContainer != null)
            {
                stacks.Add(((IMasterDetailContainer)viewContainer).MasterStack);
                stacks.Add(((IMasterDetailContainer)viewContainer).DetailStack);
            }
            else if (viewContainer as ITabbedContainer != null)
            {
                foreach (var stack in ((ITabbedContainer)viewContainer).Children)
                {
                    stacks.Add(stack);
                }
            }
            else
            {
                throw new ArgumentException($"{nameof(T)} is not a valid {nameof(IViewContainer)}. Please use one of Exrin's default types");
            }

            // Register stacks and ViewContainer Associations
            foreach (var stack in stacks)
            {
                if (!_stacks.ContainsKey(stack.StackIdentifier))
                {
                    _stacks.Add(stack.StackIdentifier, stack);
                }

                if (!_stackViewContainers.ContainsKey(stack.StackIdentifier))
                {
                    _stackViewContainers.Add(stack.StackIdentifier, viewContainer.Identifier);
                }
            }

            // Register ViewContainers
            if (!_viewContainers.ContainsKey(viewContainer.Identifier))
            {
                _viewContainers.Add(viewContainer.Identifier, viewContainer);
            }
        }