Example #1
0
        protected override void OnFinalizeBinding(DiContainer container)
        {
            var factory = new FactoryProviderWrapper <TContract>(
                _factoryBindInfo.ProviderFunc(container), new InjectContext(container, typeof(TContract)));

            var settings = new MemoryPoolSettings(
                _poolBindInfo.InitialSize, _poolBindInfo.MaxSize, _poolBindInfo.ExpandMethod);

            var transientProvider = new TransientProvider(
                _factoryBindInfo.FactoryType,
                container,
                _factoryBindInfo.Arguments.Concat(
                    InjectUtil.CreateArgListExplicit(factory, settings)).ToList(),
                BindInfo.ContextInfo, BindInfo.ConcreteIdentifier, null);

            IProvider mainProvider;

            if (BindInfo.Scope == ScopeTypes.Unset || BindInfo.Scope == ScopeTypes.Singleton)
            {
                mainProvider = BindingUtil.CreateCachedProvider(transientProvider);
            }
            else
            {
                Assert.IsEqual(BindInfo.Scope, ScopeTypes.Transient);
                mainProvider = transientProvider;
            }

            RegisterProviderForAllContracts(container, mainProvider);
        }
Example #2
0
        void FinalizeBindingSelf(DiContainer container)
        {
            var scope = GetScope();

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

            case ScopeTypes.Singleton:
            {
                RegisterProviderPerContract(
                    container,
                    (_, contractType) =>
                    BindingUtil.CreateCachedProvider(
                        _providerFactory(container, contractType)));
                break;
            }

            default:
            {
                throw Assert.CreateException();
            }
            }
        }
Example #3
0
        protected override void OnFinalizeBinding(DiContainer container)
        {
            var provider = _factoryBindInfo.ProviderFunc(container);

            var transientProvider = new TransientProvider(
                _factoryBindInfo.FactoryType,
                container,
                _factoryBindInfo.Arguments.Concat(
                    InjectUtil.CreateArgListExplicit(
                        provider,
                        new InjectContext(container, typeof(TContract)))).ToList(),
                BindInfo.ContextInfo, BindInfo.ConcreteIdentifier, null);

            IProvider mainProvider;

            if (BindInfo.Scope == ScopeTypes.Unset || BindInfo.Scope == ScopeTypes.Singleton)
            {
                mainProvider = BindingUtil.CreateCachedProvider(transientProvider);
            }
            else
            {
                Assert.IsEqual(BindInfo.Scope, ScopeTypes.Transient);
                mainProvider = transientProvider;
            }

            RegisterProviderForAllContracts(container, mainProvider);
        }
        void FinalizeBindingConcrete(DiContainer container, List <Type> concreteTypes)
        {
            var scope = GetScope();

            switch (scope)
            {
            case ScopeTypes.Transient:
            {
                RegisterProvidersForAllContractsPerConcreteType(
                    container,
                    concreteTypes,
                    (_, concreteType) =>
                    _providerFactory(
                        concreteType,
                        new PrefabInstantiator(
                            container,
                            _gameObjectBindInfo,
                            concreteType,
                            BindInfo.Arguments,
                            new PrefabProvider(_prefab),
                            BindInfo.InstantiatedCallback)));
                break;
            }

            case ScopeTypes.Singleton:
            {
                var argumentTarget = concreteTypes.OnlyOrDefault();

                if (argumentTarget == null)
                {
                    Assert.That(BindInfo.Arguments.IsEmpty(),
                                "Cannot provide arguments to prefab instantiator when using more than one concrete type");
                }

                var prefabCreator = new PrefabInstantiatorCached(
                    new PrefabInstantiator(
                        container,
                        _gameObjectBindInfo,
                        argumentTarget,
                        BindInfo.Arguments,
                        new PrefabProvider(_prefab),
                        BindInfo.InstantiatedCallback));

                RegisterProvidersForAllContractsPerConcreteType(
                    container,
                    concreteTypes,
                    (_, concreteType) => BindingUtil.CreateCachedProvider(
                        _providerFactory(concreteType, prefabCreator)));
                break;
            }

            default:
            {
                throw Assert.CreateException();
            }
            }
        }
Example #5
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();
            }
            }
        }