/*============================================================================*/
        /* Private Functions                                                          */
        /*============================================================================*/

        private void HandleContextView(object contextViewObject)
        {
            IContextView contextView = contextViewObject as IContextView;

            _contextView = contextView.view;

            if (!_injector.HasDirectMapping(typeof(IViewStateWatcher)))
            {
                _logger.Error("No IViewStateWatcher installed prior to Modularity Extension. The Modularity extension requires IViewStateWatcher to be installed first");
                return;
            }
            _contextViewStateWatcher = _injector.GetInstance(typeof(IViewStateWatcher)) as IViewStateWatcher;

            if (!_injector.HasDirectMapping(typeof(IParentFinder)))
            {
                _logger.Error("No IParentFinder Installed. The Modularity extension required this");
                return;
            }
            _parentFinder = _injector.GetInstance(typeof(IParentFinder)) as IParentFinder;

            if (_expose)
            {
                ConfigureExistenceWatcher();
            }
            if (_inherit)
            {
                ConfigureExistenceBroadcaster();
            }
        }
        public void Doesnt_Leave_View_And_Mediator_Mappings_Lying_Around()
        {
            instance.MapMatcher(new TypeMatcher().AnyOf(typeof(ObjectWhichExtendsSupportView), typeof(SupportView))).ToProcess(new MediatorCreator(typeof(SupportMediator)));
            instance.HandleView(new SupportView(), typeof(SupportView));

            Assert.That(injector.HasDirectMapping(typeof(ObjectWhichExtendsSupportView)), Is.False);
            Assert.That(injector.HasDirectMapping(typeof(SupportView)), Is.False);
            Assert.That(injector.HasDirectMapping(typeof(SupportMediator)), Is.False);
        }
        /*============================================================================*/
        /* Private Functions                                                           */
        /*============================================================================*/

        private void HandleContextView(object contextView)
        {
            if (_contextView != null)
            {
                return;
            }
            IContextView castContextView = contextView as IContextView;

            if (castContextView == null)
            {
                return;
            }
            _contextView = castContextView;

            if (_injector.HasDirectMapping(typeof(IViewStateWatcher)))
            {
                return;
            }
            IViewStateWatcher viewStateWatcher = GetViewStateWatcher(_contextView.view);

            if (viewStateWatcher == null)
            {
                _logger.Warn("Unable to create View State Watcher.");
                return;
            }
            _injector.Map(typeof(IViewStateWatcher)).ToValue(viewStateWatcher);
        }
        /*============================================================================*/
        /* Protected Functions                                                        */
        /*============================================================================*/

        protected object FromInjector(Type type)
        {
            if (!injector.HasDirectMapping(type))
            {
                injector.Map(type).AsSingleton();
            }
            return(injector.GetInstance(type));
        }
Exemple #5
0
        /*============================================================================*/
        /* Private Functions                                                          */
        /*============================================================================*/

        private void AfterInitializing()
        {
            _containerRegistry = _injector.GetInstance(typeof(ContainerRegistry)) as ContainerRegistry;
            if (!_injector.HasDirectMapping(typeof(IStageCrawler)))
            {
                _logger.Warn("No CrawlerConfig configured. Make sure to configure a platform specific stage crawler config, or don't install the StageCrawler extension");
                return;
            }
            if (_injector.HasDirectMapping(typeof(IViewManager)))
            {
                ScanViewManagedContainers();
            }
            else
            {
                ScanContextView();
            }
        }
        /*============================================================================*/
        /* Private Functions                                                          */
        /*============================================================================*/

        private void BeforeInitializing()
        {
            if (_injector.HasDirectMapping(typeof(IContextView)))
            {
                IContextView contextView = _injector.GetInstance(typeof(IContextView)) as IContextView;
                unitySingletons = (contextView.view as Transform).gameObject.AddComponent <UnitySingletons>();
                unitySingletons.SetFactory(_singletonFactory);
            }
        }
 private void BeforeInitializing()
 {
     if (_injector.HasDirectMapping(typeof(ContainerRegistry)))
     {
         ContainerRegistry registry = _injector.GetInstance(typeof(ContainerRegistry)) as ContainerRegistry;
         registry.SetParentFinder(_parentFinder);
         _injector.Unmap(typeof(IParentFinder));
         _injector.Map(typeof(IParentFinder)).ToValue(registry);
     }
 }
Exemple #8
0
        public void CreatesProcessorSingletonMappingWhereNotMapped()
        {
            List <ViewProcessorMapping> mappings = new List <ViewProcessorMapping>();

            mappings.Add(new ViewProcessorMapping(new TypeMatcher().AllOf(view.GetType()).CreateTypeFilter(), typeof(TrackingProcessor)));

            viewProcessorFactory.RunProcessors(view, view.GetType(), mappings.ToArray());

            Assert.That(injector.HasDirectMapping(typeof(TrackingProcessor)), Is.True);
        }
Exemple #9
0
        private void UnmapTypeForFilterBinding(ITypeFilter filter, Type type, object view)
        {
            List <Type> requiredTypes = RequiredTypesFor(filter, type);

            foreach (Type requiredType in requiredTypes)
            {
                if (_injector.HasDirectMapping(requiredType))
                {
                    _injector.Unmap(requiredType);
                }
            }
        }
        /*============================================================================*/
        /* Private Functions                                                          */
        /*============================================================================*/

        private void AddContextView(object contextViewObject)
        {
            IContextView contextView = contextViewObject as IContextView;

            if (!(contextView.view is UnityEngine.Transform))
            {
                _logger.Warn("Cannot map {0} as Transform for the ContextViewTransformExtension to work. Try to configure with 'new TransformContextView(transform)'", contextView.view);
                return;
            }

            if (_injector.HasDirectMapping(typeof(UnityEngine.Transform)))
            {
                _logger.Warn("A Transform has already been mapped, ignoring {0}", contextView.view);
                return;
            }

            _logger.Debug("Mapping {0} as Transform", contextView.view);
            _injector.Map(typeof(UnityEngine.Transform)).ToValue(contextView.view);
        }
		/*============================================================================*/
		/* Public Functions                                                           */
		/*============================================================================*/

		public void Extend(IContext context)
		{
			_context = context;
			_injector = context.injector;
			_logger = context.GetLogger(this);



			if (_injector.HasDirectMapping (typeof(IViewStateWatcher)))
			{
				_contextViewStateWatcher = _injector.GetMapping (typeof(IViewStateWatcher)) as IViewStateWatcher;
				Init ();
			}
			else
			{
				_context.AfterInitializing (BeforeInitializing);
			}

			_injector.Map(typeof(IModuleConnector)).ToSingleton(typeof(ModuleConnector));
		}
        /*============================================================================*/
        /* Public Functions                                                           */
        /*============================================================================*/

        public void Extend(IContext context)
        {
            context.WhenInitializing(WhenInitializing);
            context.WhenDestroying(WhenDestroying);

            _injector = context.injector;

            // Just one Container Registry
            if (_containerRegistry == null)
            {
                _containerRegistry = new ContainerRegistry();
                ViewNotifier.SetRegistry(_containerRegistry);
            }
            _injector.Map(typeof(ContainerRegistry)).ToValue(_containerRegistry);
            if (_injector.HasDirectMapping(typeof(IParentFinder)))
            {
                _injector.Unmap(typeof(IParentFinder));
            }
            _injector.Map(typeof(IParentFinder)).ToValue(_containerRegistry);

            // But you get your own View Manager
            _injector.Map(typeof(IViewManager)).ToSingleton(typeof(Impl.ViewManager));
        }
		/*============================================================================*/
		/* Public Functions                                                           */
		/*============================================================================*/

		public void Extend (IContext context)
		{
			context.WhenInitializing(WhenInitializing);
			context.WhenDestroying(WhenDestroying);

			_injector = context.injector;

			// Just one Container Registry
			if (_containerRegistry == null)
			{
				_containerRegistry = new ContainerRegistry ();
				ViewNotifier.SetRegistry (_containerRegistry);
			}
			_injector.Map(typeof(ContainerRegistry)).ToValue(_containerRegistry);
			if(_injector.HasDirectMapping(typeof(IParentFinder)))
			{
				_injector.Unmap (typeof(IParentFinder));
			}
			_injector.Map(typeof(IParentFinder)).ToValue(_containerRegistry);

			// But you get your own View Manager
			_injector.Map(typeof(IViewManager)).ToSingleton(typeof(ViewManager));
		}
Exemple #14
0
 private bool HasContextBinding()
 {
     return(_injector.HasDirectMapping(typeof(IContextView)));
 }