public IProvider CreateProvider(
            Type resultType, object concreteIdentifier, UnityEngine.Object prefab, object identifier,
            GameObjectCreationParameters gameObjectBindInfo)
        {
            _markRegistry.MarkSingleton(
                resultType, concreteIdentifier,
                SingletonTypes.FromSubContainerPrefab);

            var customSingletonId = new CustomSingletonId(
                concreteIdentifier, prefab);

            CreatorInfo creatorInfo;

            if (_subContainerCreators.TryGetValue(customSingletonId, out creatorInfo))
            {
                Assert.IsEqual(creatorInfo.GameObjectCreationParameters, gameObjectBindInfo,
                               "Ambiguous creation parameters (game object name/parent info) when using ToSubContainerPrefab with AsSingle");
            }
            else
            {
                var creator = new SubContainerCreatorCached(
                    new SubContainerCreatorByNewPrefab(_container, new PrefabProvider(prefab), gameObjectBindInfo));

                creatorInfo = new CreatorInfo(gameObjectBindInfo, creator);

                _subContainerCreators.Add(customSingletonId, creatorInfo);
            }

            return(new SubContainerDependencyProvider(
                       resultType, identifier, creatorInfo.Creator));
        }
예제 #2
0
        public IProvider CreateProvider(
            Type resultType, object concreteIdentifier,
            Action <DiContainer> installMethod, object identifier)
        {
            _markRegistry.MarkSingleton(
                new SingletonId(resultType, concreteIdentifier),
                SingletonTypes.FromSubContainerMethod);

            ISubContainerCreator subContainerCreator;

            var subContainerSingletonId = new MethodSingletonId(
                concreteIdentifier, installMethod);

            if (!_subContainerCreators.TryGetValue(subContainerSingletonId, out subContainerCreator))
            {
                subContainerCreator = new SubContainerCreatorCached(
                    new SubContainerCreatorByMethod(
                        _container, installMethod));

                _subContainerCreators.Add(subContainerSingletonId, subContainerCreator);
            }

            return(new SubContainerDependencyProvider(
                       resultType, identifier, subContainerCreator));
        }
        void FinalizeBindingConcrete(DiContainer container, List <Type> concreteTypes)
        {
            switch (GetScope())
            {
            case ScopeTypes.Singleton:
            {
                RegisterProvidersForAllContractsPerConcreteType(
                    container,
                    concreteTypes,
                    (_, concreteType) => container.SingletonProviderCreator.CreateProviderForSubContainerPrefab(
                        concreteType,
                        BindInfo.ConcreteIdentifier,
                        _gameObjectBindInfo,
                        _prefab,
                        _subIdentifier));
                break;
            }

            case ScopeTypes.Transient:
            {
                RegisterProvidersForAllContractsPerConcreteType(
                    container,
                    concreteTypes,
                    (_, concreteType) => new SubContainerDependencyProvider(
                        concreteType, _subIdentifier,
                        new SubContainerCreatorByNewPrefab(
                            container, new PrefabProvider(_prefab), _gameObjectBindInfo)));
                break;
            }

            case ScopeTypes.Cached:
            {
                var containerCreator = new SubContainerCreatorCached(
                    new SubContainerCreatorByNewPrefab(
                        container, new PrefabProvider(_prefab), _gameObjectBindInfo));

                RegisterProvidersForAllContractsPerConcreteType(
                    container,
                    concreteTypes,
                    (_, concreteType) =>
                    new SubContainerDependencyProvider(
                        concreteType, _subIdentifier, containerCreator));
                break;
            }

            default:
            {
                throw Assert.CreateException();
            }
            }
        }
예제 #4
0
        void FinalizeBindingConcrete(DiContainer container, List <Type> concreteTypes)
        {
            switch (GetScope())
            {
            case ScopeTypes.Singleton:
            {
                RegisterProvidersForAllContractsPerConcreteType(
                    container,
                    concreteTypes,
                    (_, concreteType) =>
                    container.SingletonProviderCreator.CreateProviderForSubContainerMethod(
                        concreteType,
                        BindInfo.ConcreteIdentifier,
                        _installMethod,
                        _subIdentifier));
                break;
            }

            case ScopeTypes.Transient:
            {
                // Note: each contract/concrete pair gets its own container here
                RegisterProvidersPerContractAndConcreteType(
                    container,
                    concreteTypes,
                    (contractType, concreteType) => new SubContainerDependencyProvider(
                        concreteType, _subIdentifier,
                        new SubContainerCreatorByMethod(container, _installMethod)));
                break;
            }

            case ScopeTypes.Cached:
            {
                var creator = new SubContainerCreatorCached(
                    new SubContainerCreatorByMethod(container, _installMethod));

                // Note: each contract/concrete pair gets its own container
                RegisterProvidersForAllContractsPerConcreteType(
                    container,
                    concreteTypes,
                    (_, concreteType) => new SubContainerDependencyProvider(
                        concreteType, _subIdentifier, creator));
                break;
            }

            default:
            {
                throw Assert.CreateException();
            }
            }
        }
예제 #5
0
        void FinalizeBindingSelf(DiContainer container)
        {
            switch (GetScope())
            {
            case ScopeTypes.Singleton:
            {
                RegisterProviderPerContract(
                    container,
                    (_, contractType) => container.SingletonProviderCreator.CreateProviderForSubContainerPrefabResource(
                        contractType,
                        BindInfo.ConcreteIdentifier,
                        _gameObjectBindInfo,
                        _resourcePath,
                        _subIdentifier));
                break;
            }

            case ScopeTypes.Transient:
            {
                RegisterProviderPerContract(
                    container,
                    (_, contractType) => new SubContainerDependencyProvider(
                        contractType, _subIdentifier,
                        new SubContainerCreatorByNewPrefab(
                            container, new PrefabProviderResource(_resourcePath), _gameObjectBindInfo)));
                break;
            }

            case ScopeTypes.Cached:
            {
                var containerCreator = new SubContainerCreatorCached(
                    new SubContainerCreatorByNewPrefab(
                        container, new PrefabProviderResource(_resourcePath), _gameObjectBindInfo));

                RegisterProviderPerContract(
                    container,
                    (_, contractType) =>
                    new SubContainerDependencyProvider(
                        contractType, _subIdentifier, containerCreator));
                break;
            }

            default:
            {
                throw Assert.CreateException();
            }
            }
        }
예제 #6
0
        void FinalizeBindingSelf(DiContainer container)
        {
            switch (GetScope())
            {
            case ScopeTypes.Singleton:
            {
                RegisterProviderPerContract(
                    container,
                    (_, contractType) => container.SingletonProviderCreator.CreateProviderForSubContainerMethod(
                        contractType,
                        BindInfo.ConcreteIdentifier,
                        _installMethod,
                        _subIdentifier));
                break;
            }

            case ScopeTypes.Transient:
            {
                RegisterProviderPerContract(
                    container,
                    (_, contractType) => new SubContainerDependencyProvider(
                        contractType, _subIdentifier,
                        new SubContainerCreatorByMethod(
                            container, _installMethod)));
                break;
            }

            case ScopeTypes.Cached:
            {
                var containerCreator = new SubContainerCreatorCached(
                    new SubContainerCreatorByMethod(container, _installMethod));

                RegisterProviderPerContract(
                    container,
                    (_, contractType) =>
                    new SubContainerDependencyProvider(
                        contractType, _subIdentifier, containerCreator));
                break;
            }

            default:
            {
                throw Assert.CreateException();
            }
            }
        }
        public IProvider CreateProvider(
            Type resultType, object concreteIdentifier, Type installerType, object identifier)
        {
            _markRegistry.MarkSingleton(
                resultType, concreteIdentifier,
                SingletonTypes.FromSubContainerInstaller);

            var subContainerSingletonId = new InstallerSingletonId(
                concreteIdentifier, installerType);

            ISubContainerCreator subContainerCreator;

            if (!_subContainerCreators.TryGetValue(subContainerSingletonId, out subContainerCreator))
            {
                subContainerCreator = new SubContainerCreatorCached(
                    new SubContainerCreatorByInstaller(
                        _container, installerType));

                _subContainerCreators.Add(subContainerSingletonId, subContainerCreator);
            }

            return(new SubContainerDependencyProvider(
                       resultType, identifier, subContainerCreator));
        }