Пример #1
0
        public NameTransformScopeConcreteIdArgConditionCopyNonLazyBinder FromNewComponentOnNewPrefabResource(string resourcePath)
        {
            BindingUtil.AssertIsValidResourcePath(resourcePath);
            BindingUtil.AssertIsComponent(ContractType);
            BindingUtil.AssertIsNotAbstract(ContractType);

            var gameObjectInfo = new GameObjectCreationParameters();

            ProviderFunc =
                (container) => new InstantiateOnPrefabComponentProvider(
                    ContractType,
                    new PrefabInstantiator(
                        container, gameObjectInfo,
                        ContractType, new [] { ContractType }, BindInfo.Arguments,
                        new PrefabProviderResource(resourcePath),
                        BindInfo.InstantiatedCallback));

            return(new NameTransformScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo, gameObjectInfo));
        }
Пример #2
0
        public NameTransformScopeConcreteIdArgConditionCopyNonLazyBinder ByNewContextPrefab(Type installerType, UnityEngine.Object prefab)
        {
            BindingUtil.AssertIsValidPrefab(prefab);

            Assert.That(installerType.DerivesFrom <MonoInstaller>(),
                        "Invalid installer type given during bind command.  Expected type '{0}' to derive from 'MonoInstaller'", installerType);

            var gameObjectInfo = new GameObjectCreationParameters();

            ProviderFunc =
                (container) => new SubContainerDependencyProvider(
                    ContractType, SubIdentifier,
                    new SubContainerCreatorByNewPrefabWithParams(
                        installerType,
                        container,
                        new PrefabProvider(prefab),
                        gameObjectInfo), false);

            return(new NameTransformScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo, gameObjectInfo));
        }
Пример #3
0
        public NameTransformScopeConcreteIdArgConditionCopyNonLazyBinder ByNewPrefabResourceMethod(
            string resourcePath,
#if !NET_4_6 && !NET_STANDARD_2_0
            ModestTree.Util.
#endif
            Action <DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TParam9, TParam10> installerMethod)
        {
            BindingUtil.AssertIsValidResourcePath(resourcePath);

            var gameObjectInfo = new GameObjectCreationParameters();

            ProviderFunc =
                (container) => new SubContainerDependencyProvider(
                    ContractType, SubIdentifier,
                    new SubContainerCreatorByNewPrefabMethod <TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TParam9, TParam10>(container,
                                                                                                                                                         new PrefabProviderResource(resourcePath),
                                                                                                                                                         gameObjectInfo, installerMethod), false);

            return(new NameTransformScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo, gameObjectInfo));
        }
Пример #4
0
        public NameTransformScopeConcreteIdArgConditionCopyNonLazyBinder ByNewPrefabMethod(
            UnityEngine.Object prefab,
#if !NET_4_6 && !NET_STANDARD_2_0
            ModestTree.Util.
#endif
            Action <DiContainer, TParam1, TParam2, TParam3, TParam4> installerMethod)
        {
            BindingUtil.AssertIsValidPrefab(prefab);

            var gameObjectInfo = new GameObjectCreationParameters();

            ProviderFunc =
                (container) => new SubContainerDependencyProvider(
                    ContractType, SubIdentifier,
                    new SubContainerCreatorByNewPrefabMethod <TParam1, TParam2, TParam3, TParam4>(
                        container,
                        new PrefabProvider(prefab),
                        gameObjectInfo, installerMethod), false);

            return(new NameTransformScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo, gameObjectInfo));
        }
Пример #5
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);
        }
Пример #6
0
        void FinalizeBindingConcrete(DiContainer container, List <Type> concreteTypes)
        {
            if (concreteTypes.Count == 0)
            {
                // This can be common when using convention based bindings
                return;
            }

            var scope = GetScope();

            switch (scope)
            {
            case ScopeTypes.Transient:
            {
                RegisterProvidersForAllContractsPerConcreteType(
                    container, concreteTypes, _providerFactory);
                break;
            }

            case ScopeTypes.Singleton:
            {
                RegisterProvidersForAllContractsPerConcreteType(
                    container,
                    concreteTypes,
                    (_, concreteType) =>
                    BindingUtil.CreateCachedProvider(
                        _providerFactory(container, concreteType)));
                break;
            }

            default:
            {
                throw Assert.CreateException();
            }
            }
        }
Пример #7
0
        public ScopeConcreteIdArgConditionCopyNonLazyBinder FromComponentInChildren(
            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 FromComponentInChildren to inject data into non monobehaviours!");

                Assert.IsNotNull(ctx.ObjectInstance);

                var monoBehaviour = (MonoBehaviour)ctx.ObjectInstance;

                var match = monoBehaviour.GetComponentInChildren(concreteType, includeInactive);

                if (match == null)
                {
                    Assert.That(ctx.Optional,
                                "Could not find any component with type '{0}' through FromComponentInChildren binding", concreteType);
                    return(Enumerable.Empty <object>());
                }

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

            return(this);
        }
Пример #8
0
 public ScopeConcreteIdArgConditionCopyNonLazyBinder FromMethodMultiple <TConcrete>(Func <InjectContext, IEnumerable <TConcrete> > method)
 {
     BindingUtil.AssertIsDerivedFromTypes(typeof(TConcrete), AllParentTypes);
     return(FromMethodMultipleBase <TConcrete>(method));
 }