Esempio n. 1
0
        void InstallNonInjectedBinding(ZenjectBinding.BindTypes bindType, string identifier, Component component)
        {
            switch (bindType)
            {
            case ZenjectBinding.BindTypes.Self:
            {
                _container.Bind(component.GetType()).WithId(identifier).FromInstance(component, true);
                break;
            }

            case ZenjectBinding.BindTypes.BaseType:
            {
                _container.Bind(component.GetType().BaseType()).WithId(identifier).FromInstance(component, true);
                break;
            }

            case ZenjectBinding.BindTypes.AllInterfaces:
            {
                _container.BindAllInterfaces(component.GetType()).WithId(identifier).FromInstance(component, true);
                break;
            }

            case ZenjectBinding.BindTypes.AllInterfacesAndSelf:
            {
                _container.BindAllInterfacesAndSelf(component.GetType()).WithId(identifier).FromInstance(component, true);
                break;
            }

            default:
            {
                throw Assert.CreateException();
            }
            }
        }
Esempio n. 2
0
        void InstallZenjectBinding(ZenjectBinding binding)
        {
            if (!binding.enabled)
            {
                return;
            }

            if (binding.Components == null || binding.Components.IsEmpty())
            {
                ModestTree.Log.Warn("Found empty list of components on ZenjectBinding on object '{0}'", binding.name);
                return;
            }

            string identifier = null;

            if (binding.Identifier.Trim().Length > 0)
            {
                identifier = binding.Identifier;
            }

            foreach (Component component in binding.Components)
            {
                ZenjectBinding.BindTypes bindType = binding.BindType;

                if (component == null)
                {
                    ModestTree.Log.Warn("Found null component in ZenjectBinding on object '{0}'", binding.name);
                    continue;
                }

                Type componentType = component.GetType();

                switch (bindType)
                {
                case ZenjectBinding.BindTypes.Self:
                {
                    Container.Bind(componentType).WithId(identifier).FromInstance(component);
                    break;
                }

                case ZenjectBinding.BindTypes.BaseType:
                {
                    Container.Bind(componentType.BaseType()).WithId(identifier).FromInstance(component);
                    break;
                }

                case ZenjectBinding.BindTypes.AllInterfaces:
                {
                    Container.Bind(componentType.Interfaces()).WithId(identifier).FromInstance(component);
                    break;
                }

                case ZenjectBinding.BindTypes.AllInterfacesAndSelf:
                {
                    Container.Bind(componentType.Interfaces().Concat(new[] { componentType }).ToArray()).WithId(identifier).FromInstance(component);
                    break;
                }

                default:
                {
                    throw Assert.CreateException();
                }
                }
            }
        }