protected ScopeConcreteIdArgConditionCopyNonLazyBinder FromMethodMultipleBase <TConcrete>(
            Func <InjectContext, IEnumerable <TConcrete> > method)
        {
            BindInfo.RequireExplicitScope = false;
            // Don't know how it's created so can't assume here that it violates AsSingle
            BindInfo.MarkAsCreationBinding = false;
            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                (container, type) => new MethodProviderMultiple <TConcrete>(method, container));

            return(this);
        }
Example #2
0
        protected ScopeBinder FromFactoryBase <TConcrete, TFactory>()
            where TFactory : IFactory <TConcrete>
        {
            BindingUtil.AssertIsDerivedFromTypes(typeof(TConcrete), AllParentTypes);

            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                SingletonTypes.ToFactory, typeof(TFactory),
                (container, type) => new FactoryProvider <TConcrete, TFactory>(container, new List <TypeValuePair>()));

            return(new ScopeBinder(BindInfo));
        }
Example #3
0
        public ScopeBinder FromResource(string resourcePath)
        {
            BindingUtil.AssertDerivesFromUnityObject(ConcreteTypes);

            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                SingletonTypes.ToResource,
                resourcePath.ToLower(),
                (_, type) => new ResourceProvider(resourcePath, type));

            return(new ScopeBinder(BindInfo));
        }
        protected ScopeArgConditionCopyNonLazyBinder FromMethodMultipleBase <TConcrete>(Func <InjectContext, IEnumerable <TConcrete> > method)
        {
            BindingUtil.AssertIsDerivedFromTypes(typeof(TConcrete), AllParentTypes);

            BindInfo.RequireExplicitScope = false;
            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                SingletonTypes.FromMethod, new SingletonImplIds.ToMethod(method),
                (container, type) => new MethodProviderMultiple <TConcrete>(method, container));

            return(this);
        }
        // Note that this is the default, so not necessary to call
        public FromBinderNonGeneric ToSelf()
        {
            Assert.IsEqual(BindInfo.ToChoice, ToChoices.Self);

            BindInfo.RequireExplicitScope = true;
            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo, (container, type) => new TransientProvider(
                    type, container, BindInfo.Arguments, BindInfo.ContextInfo, BindInfo.ConcreteIdentifier,
                    BindInfo.InstantiatedCallback));

            return(this);
        }
Example #6
0
        public ScopeBinder FromFactory(Type factoryType)
        {
            Assert.That(factoryType.DerivesFrom <IFactory>());

            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                SingletonTypes.ToFactory, factoryType,
                (container, type) => new UntypedFactoryProvider(
                    factoryType, container, new List <TypeValuePair>()));

            return(new ScopeBinder(BindInfo));
        }
        public ScopeConditionCopyNonLazyBinder FromResource(string resourcePath)
        {
            BindingUtil.AssertDerivesFromUnityObject(ConcreteTypes);

            BindInfo.RequireExplicitScope = false;
            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                SingletonTypes.FromResource,
                resourcePath.ToLower(),
                (_, type) => new ResourceProvider(resourcePath, type));

            return(new ScopeConditionCopyNonLazyBinder(BindInfo));
        }
Example #8
0
        protected ScopeConcreteIdArgConditionCopyNonLazyBinder FromMethodBase <TConcrete>(Func <InjectContext, TConcrete> method)
        {
            BindingUtil.AssertIsDerivedFromTypes(typeof(TConcrete), AllParentTypes);

            BindInfo.RequireExplicitScope = false;
            // Don't know how it's created so can't assume here that it violates AsSingle
            BindInfo.MarkAsCreationBinding = false;
            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                (container, type) => new MethodProvider <TConcrete>(method, container));

            return(this);
        }
Example #9
0
        ScopeConcreteIdArgConditionCopyNonLazyBinder FromScriptableObjectInternal(
            ScriptableObject resource, bool createNew)
        {
            BindingUtil.AssertIsInterfaceOrScriptableObject(AllParentTypes);

            BindInfo.RequireExplicitScope = true;
            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                (container, type) => new ScriptableObjectProvider(
                    resource, type, container, BindInfo.ConcreteIdentifier, BindInfo.Arguments, createNew));

            return(new ScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo));
        }
Example #10
0
        public ScopeArgBinder FromComponent(GameObject gameObject)
        {
            BindingUtil.AssertIsValidGameObject(gameObject);
            BindingUtil.AssertIsComponent(ConcreteTypes);
            BindingUtil.AssertTypesAreNotAbstract(ConcreteTypes);

            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo, SingletonTypes.ToComponentGameObject, gameObject,
                (container, type) => new AddToExistingGameObjectComponentProvider(
                    gameObject, container, type, BindInfo.ConcreteIdentifier, BindInfo.Arguments));

            return(new ScopeArgBinder(BindInfo));
        }
Example #11
0
        protected ScopeBinder FromResolveGetterBase <TObj, TResult>(
            object identifier, Func <TObj, TResult> method)
        {
            BindingUtil.AssertIsDerivedFromTypes(typeof(TResult), AllParentTypes);

            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                SingletonTypes.ToGetter,
                new SingletonImplIds.ToGetter(identifier, method),
                (container, type) => new GetterProvider <TObj, TResult>(identifier, method, container));

            return(new ScopeBinder(BindInfo));
        }
Example #12
0
        public ScopeArgConditionCopyNonLazyBinder FromFactory(Type factoryType)
        {
            Assert.That(factoryType.DerivesFrom <IFactory>());

            BindInfo.RequireExplicitScope = true;
            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                SingletonTypes.FromFactory, factoryType,
                (container, type) => new UntypedFactoryProvider(
                    factoryType, container, BindInfo.Arguments));

            return(new ScopeArgConditionCopyNonLazyBinder(BindInfo));
        }
Example #13
0
        protected ScopeConcreteIdArgConditionCopyNonLazyBinder FromInstanceBase(object instance)
        {
            BindingUtil.AssertInstanceDerivesFromOrEqual(instance, AllParentTypes);

            BindInfo.RequireExplicitScope = false;
            // Don't know how it's created so can't assume here that it violates AsSingle
            BindInfo.MarkAsCreationBinding = false;
            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                (container, type) => new InstanceProvider(type, instance, container));

            return(new ScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo));
        }
Example #14
0
        ScopeConcreteIdArgConditionCopyNonLazyBinder FromResolveInternal(object subIdentifier, bool matchAll, InjectSources source)
        {
            BindInfo.RequireExplicitScope = false;
            // Don't know how it's created so can't assume here that it violates AsSingle
            BindInfo.MarkAsCreationBinding = false;

            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                (container, type) => new ResolveProvider(
                    type, container, subIdentifier, false, source, matchAll));

            return(new ScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo));
        }
Example #15
0
        public ScopeConcreteIdArgConditionCopyNonLazyBinder FromNewComponentOn(Func <InjectContext, GameObject> gameObjectGetter)
        {
            BindingUtil.AssertIsComponent(ConcreteTypes);
            BindingUtil.AssertTypesAreNotAbstract(ConcreteTypes);

            BindInfo.RequireExplicitScope = true;
            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                (container, type) => new AddToExistingGameObjectComponentProviderGetter(
                    gameObjectGetter, container, type, BindInfo.Arguments, BindInfo.ConcreteIdentifier, BindInfo.InstantiatedCallback));

            return(new ScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo));
        }
Example #16
0
        public ScopeConcreteIdArgConditionCopyNonLazyBinder FromComponentOn(Func <InjectContext, GameObject> gameObjectGetter)
        {
            BindingUtil.AssertIsComponent(ConcreteTypes);
            BindingUtil.AssertTypesAreNotAbstract(ConcreteTypes);

            BindInfo.RequireExplicitScope = false;
            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                (container, type) => new GetFromGameObjectGetterComponentProvider(
                    type, gameObjectGetter, true));

            return(new ScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo));
        }
Example #17
0
        protected ScopeArgConditionCopyNonLazyBinder FromFactoryBase <TConcrete, TFactory>()
            where TFactory : IFactory <TConcrete>
        {
            BindingUtil.AssertIsDerivedFromTypes(typeof(TConcrete), AllParentTypes);

            // This is kind of like a look up method like FromMethod so don't enforce specifying scope
            BindInfo.RequireExplicitScope = false;
            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                SingletonTypes.FromFactory, typeof(TFactory),
                (container, type) => new FactoryProvider <TConcrete, TFactory>(container, BindInfo.Arguments));

            return(new ScopeArgConditionCopyNonLazyBinder(BindInfo));
        }
        public ScopeConcreteIdArgConditionCopyNonLazyBinder FromNewComponentOn(GameObject gameObject)
        {
            BindingUtil.AssertIsValidGameObject(gameObject);
            BindingUtil.AssertIsComponent(ConcreteTypes);
            BindingUtil.AssertTypesAreNotAbstract(ConcreteTypes);

            BindInfo.RequireExplicitScope = true;
            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                (container, type) => new AddToExistingGameObjectComponentProvider(
                    gameObject, container, type, BindInfo.Arguments, BindInfo.ConcreteIdentifier));

            return(new ScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo));
        }
Example #19
0
        public ScopeConcreteIdArgConditionCopyNonLazyBinder FromComponentsOn(GameObject gameObject)
        {
            BindingUtil.AssertIsValidGameObject(gameObject);
            BindingUtil.AssertIsComponent(ConcreteTypes);
            BindingUtil.AssertTypesAreNotAbstract(ConcreteTypes);

            BindInfo.RequireExplicitScope = true;
            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                (container, type) => new GetFromGameObjectComponentProvider(
                    type, gameObject, false));

            return(new ScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo));
        }
Example #20
0
        protected ScopeConcreteIdArgConditionCopyNonLazyBinder FromResolveGetterBase <TObj, TResult>(
            object identifier, Func <TObj, TResult> method, InjectSources source, bool matchMultiple)
        {
            BindingUtil.AssertIsDerivedFromTypes(typeof(TResult), AllParentTypes);

            BindInfo.RequireExplicitScope = false;
            // Don't know how it's created so can't assume here that it violates AsSingle
            BindInfo.MarkAsCreationBinding = false;
            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                (container, type) => new GetterProvider <TObj, TResult>(identifier, method, container, source, matchMultiple));

            return(new ScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo));
        }
Example #21
0
        public ScopeArgConditionCopyNonLazyBinder FromScriptableObjectResource(string resourcePath)
        {
            BindingUtil.AssertIsValidResourcePath(resourcePath);
            BindingUtil.AssertIsInterfaceOrScriptableObject(AllParentTypes);

            BindInfo.RequireExplicitScope = true;
            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                SingletonTypes.FromScriptableObjectResource,
                resourcePath.ToLower(),
                (container, type) => new ScriptableObjectResourceProvider(
                    resourcePath, type, container, BindInfo.ConcreteIdentifier, BindInfo.Arguments));

            return(new ScopeArgConditionCopyNonLazyBinder(BindInfo));
        }
Example #22
0
        ScopeConcreteIdArgConditionCopyNonLazyBinder FromScriptableObjectResourceInternal(
            string resourcePath, bool createNew)
        {
            BindingUtil.AssertIsValidResourcePath(resourcePath);
            BindingUtil.AssertIsInterfaceOrScriptableObject(AllParentTypes);

            BindInfo.RequireExplicitScope = true;
            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                (container, type) => new ScriptableObjectResourceProvider(
                    resourcePath, type, container, BindInfo.Arguments, createNew,
                    BindInfo.ConcreteIdentifier, BindInfo.InstantiatedCallback));

            return(new ScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo));
        }
Example #23
0
        protected ScopeBinder FromInstanceBase(object instance, bool allowNull)
        {
            if (!allowNull)
            {
                Assert.That(!ZenUtilInternal.IsNull(instance),
                            "Found null instance for type '{0}' in FromInstance method",
                            ConcreteTypes.First().Name());
            }

            BindingUtil.AssertInstanceDerivesFromOrEqual(instance, AllParentTypes);

            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo, SingletonTypes.ToInstance, instance,
                (container, type) => new InstanceProvider(container, type, instance));

            return(new ScopeBinder(BindInfo));
        }
Example #24
0
        internal NameTransformScopeConcreteIdArgConditionCopyNonLazyBinder FromNewComponentOnNewGameObject(
            GameObjectCreationParameters gameObjectInfo)
        {
            BindingUtil.AssertIsComponent(ConcreteTypes);
            BindingUtil.AssertTypesAreNotAbstract(ConcreteTypes);

            BindInfo.RequireExplicitScope = true;
            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                (container, type) => new AddToNewGameObjectComponentProvider(
                    container,
                    type,
                    BindInfo.Arguments,
                    gameObjectInfo, BindInfo.ConcreteIdentifier, BindInfo.InstantiatedCallback));

            return(new NameTransformScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo, gameObjectInfo));
        }
Example #25
0
        public ScopeConcreteIdArgConditionCopyNonLazyBinder FromComponentInParents(
            bool excludeSelf = false, bool includeInactive = true)
        {
            BindingUtil.AssertIsInterfaceOrComponent(AllParentTypes);

            BindInfo.RequireExplicitScope = false;

            // Don't know how it's created so can't assume here that it violates AsSingle
            BindInfo.MarkAsCreationBinding = false;

            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                (container, concreteType) => new MethodMultipleProviderUntyped(ctx =>
            {
                Assert.That(ctx.ObjectType.DerivesFromOrEqual <MonoBehaviour>(),
                            "Cannot use FromComponentSibling to inject data into non monobehaviours!");

                Assert.IsNotNull(ctx.ObjectInstance);

                var monoBehaviour = (MonoBehaviour)ctx.ObjectInstance;

                var matches = monoBehaviour.GetComponentsInParent(concreteType, includeInactive)
                              .Where(x => !ReferenceEquals(x, ctx.ObjectInstance));

                if (excludeSelf)
                {
                    matches = matches.Where(x => x.gameObject != monoBehaviour.gameObject);
                }

                var match = matches.FirstOrDefault();

                if (match == null)
                {
                    Assert.That(ctx.Optional,
                                "Could not find any component with type '{0}' through FromComponentInParents binding", concreteType);

                    return(Enumerable.Empty <object>());
                }

                return(new object[] { match });
            },
                                                                               container));

            return(this);
        }
        public AsyncFromBinderBase FromAssetReferenceT <TConcreteObj>(AssetReferenceT <TConcreteObj> reference)
            where TConcreteObj : UnityEngine.Object, TConcrete
        {
            BindInfo.RequireExplicitScope = false;

            var contractType = typeof(TContract);

            if (typeof(UnityEngine.Object).IsAssignableFrom(contractType))
            {
                var addressableInjectType = typeof(AddressableInject <>).MakeGenericType(typeof(TContract));
                BindInfo.ContractTypes.Add(addressableInjectType);
            }

            // Don't know how it's created so can't assume here that it violates AsSingle
            BindInfo.MarkAsCreationBinding = false;
            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                (container, originalType) => new AddressableProviderSimple <TContract, TConcreteObj>(reference));

            return(this);
        }
Example #27
0
        protected ScopeConcreteIdArgConditionCopyNonLazyBinder FromComponentsInChildrenBase(
            bool excludeSelf, Func <Component, bool> predicate, bool includeInactive)
        {
            BindingUtil.AssertIsInterfaceOrComponent(AllParentTypes);

            BindInfo.RequireExplicitScope = false;

            // Don't know how it's created so can't assume here that it violates AsSingle
            BindInfo.MarkAsCreationBinding = false;

            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                (container, concreteType) => new MethodMultipleProviderUntyped(ctx =>
            {
                Assert.That(ctx.ObjectType.DerivesFromOrEqual <MonoBehaviour>(),
                            "Cannot use FromComponentsInChildren to inject data into non monobehaviours!");

                Assert.IsNotNull(ctx.ObjectInstance);

                var monoBehaviour = (MonoBehaviour)ctx.ObjectInstance;

                var res = monoBehaviour.GetComponentsInChildren(concreteType, includeInactive)
                          .Where(x => !ReferenceEquals(x, ctx.ObjectInstance));

                if (excludeSelf)
                {
                    res = res.Where(x => x.gameObject != monoBehaviour.gameObject);
                }

                if (predicate != null)
                {
                    res = res.Where(predicate);
                }

                return(res.Cast <object>());
            },
                                                                               container));

            return(this);
        }
Example #28
0
        public GameObjectNameGroupNameScopeArgBinder FromGameObject()
        {
            BindingUtil.AssertIsAbstractOrComponentOrGameObject(BindInfo.ContractTypes);
            BindingUtil.AssertIsComponentOrGameObject(ConcreteTypes);

            var gameObjectInfo = new GameObjectBindInfo();

            if (ConcreteTypes.All(x => x == typeof(GameObject)))
            {
                SubFinalizer = new ScopableBindingFinalizer(
                    BindInfo, SingletonTypes.ToGameObject, gameObjectInfo,
                    (container, type) =>
                {
                    Assert.That(BindInfo.Arguments.IsEmpty(), "Cannot inject arguments into empty game object");
                    return(new EmptyGameObjectProvider(
                               container, gameObjectInfo.Name, gameObjectInfo.GroupName));
                });
            }
            else
            {
                BindingUtil.AssertIsComponent(ConcreteTypes);
                BindingUtil.AssertTypesAreNotAbstract(ConcreteTypes);

                SubFinalizer = new ScopableBindingFinalizer(
                    BindInfo, SingletonTypes.ToGameObject, gameObjectInfo,
                    (container, type) => new AddToNewGameObjectComponentProvider(
                        container,
                        type,
                        BindInfo.ConcreteIdentifier,
                        BindInfo.Arguments,
                        gameObjectInfo.Name,
                        gameObjectInfo.GroupName));
            }

            return(new GameObjectNameGroupNameScopeArgBinder(BindInfo, gameObjectInfo));
        }