示例#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);
        }
示例#2
0
        void Construct(
            IFactory <TContract> factory,
            DiContainer container,
            MemoryPoolSettings settings)
        {
            _settings = settings;
            _factory  = factory;

            _inactiveItems = new Stack <TContract>(settings.InitialSize);

            if (!container.IsValidating)
            {
                for (int i = 0; i < settings.InitialSize; i++)
                {
                    _inactiveItems.Push(AllocNew());
                }
            }
        }
        protected override void OnFinalizeBinding(DiContainer container)
        {
            FactoryProviderWrapper <TContract> factory = new FactoryProviderWrapper <TContract>(
                _factoryBindInfo.ProviderFunc(container), new InjectContext(container, typeof(TContract)));

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

            RegisterProviderForAllContracts(
                container,
                BindingUtil.CreateCachedProvider(
                    new TransientProvider(
                        _factoryBindInfo.FactoryType,
                        container,
                        _factoryBindInfo.Arguments.Concat(
                            InjectUtil.CreateArgListExplicit(factory, settings)).ToList(),
                        BindInfo.ContextInfo, BindInfo.ConcreteIdentifier)));
        }
        protected override void OnFinalizeBinding(DiContainer container)
        {
            var factory = new FactoryProviderWrapper <TContract>(
                _factoryBindInfo.ProviderFunc(container), new InjectContext(container, typeof(TContract)));

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

            RegisterProviderForAllContracts(
                container,
                new CachedProvider(
                    new TransientProvider(
                        _factoryBindInfo.FactoryType,
                        container,
                        InjectUtil.CreateArgListExplicit(factory, settings),
                        null,
                        BindInfo.ContextInfo)));
        }
示例#5
0
        void Construct(
            IFactory <TContract> factory,
            DiContainer container,
            [InjectOptional]
            MemoryPoolSettings settings)
        {
            _settings  = settings ?? MemoryPoolSettings.Default;
            _factory   = factory;
            _container = container;

            _inactiveItems = new Stack <TContract>(_settings.InitialSize);

            if (!container.IsValidating)
            {
                for (int i = 0; i < _settings.InitialSize; i++)
                {
                    _inactiveItems.Push(AllocNew());
                }
            }

            StaticMemoryPoolRegistry.Add(this);
        }