Example #1
0
        /// <summary>
        /// Get the currently wrapped strategy if one exists
        /// </summary>
        /// <returns></returns>
        public IActivationStrategy GetWrappedStrategy()
        {
            IActivationStrategy returnStrategy = null;

            _wrapperNodes?.Visit(p =>
            {
                if (p.Strategy.StrategyType == ActivationStrategyType.ExportStrategy)
                {
                    returnStrategy = p.Strategy;
                }
            });

            return(returnStrategy);
        }
        private ICompiledExportStrategy CreateExportStrategyForType(Type type, ImmutableLinkedList <Type> exportTypes, ImmutableLinkedList <Tuple <Type, object> > keyedExports, ImmutableLinkedList <string> names)
        {
            var strategy = _strategyCreator.GetCompiledExportStrategy(type);

            foreach (var exportType in exportTypes)
            {
                strategy.AddExportAs(exportType);
            }

            foreach (var keyedExport in keyedExports)
            {
                strategy.AddExportAsKeyed(keyedExport.Item1, keyedExport.Item2);
            }

            foreach (var name in names)
            {
                strategy.AddExportAsName(name);
            }

            strategy.Lifestyle = _lifestyleFunc?.Invoke(type);

            _inspectors.Visit(i => i.Inspect(strategy), true);

            if (_exportByAttributes)
            {
                strategy.ProcessAttributeForStrategy();
            }

            _conditions.Visit(func =>
            {
                foreach (var condition in func(type))
                {
                    strategy.AddCondition(condition);
                }
            }, true);

            strategy.ExternallyOwned = _externallyOwned;

            if (_exportByAttributes)
            {
                ProcessAttributes(type, strategy);
            }

            strategy.ConstructorSelectionMethod = _constructorSelectionMethod?.Invoke(type);

            return(strategy);
        }
Example #3
0
        /// <summary>
        /// Add strategy to container
        /// </summary>
        /// <param name="strategy">strategy</param>
        public void AddStrategy(T strategy)
        {
            Inspectors.Visit(inspector => inspector.Inspect(strategy), true);

            var types = ImmutableHashTree <Type, bool> .Empty;

            foreach (var type in strategy.ExportAs)
            {
                if (ExportAsBase)
                {
                    foreach (var exportType in GetTypes(type))
                    {
                        types = types.Add(exportType, true, (value, newValue) => value);
                    }
                }
                else
                {
                    types = types.Add(type, true, (value, newValue) => value);
                }
            }

            var added = false;

            foreach (var pair in types)
            {
                added = true;

                AddStrategyByAs(strategy, pair.Key, null);
            }

            foreach (var keyedPair in strategy.ExportAsKeyed)
            {
                added = true;

                if (ExportAsBase)
                {
                    foreach (var exportType in GetTypes(keyedPair.Key))
                    {
                        AddStrategyByAs(strategy, exportType, keyedPair.Value);
                    }
                }
                else
                {
                    AddStrategyByAs(strategy, keyedPair.Key, keyedPair.Value);
                }
            }

            foreach (var name in strategy.ExportAsName)
            {
                added = true;

                AddStrategyByName(strategy, name);
            }

            if (!added)
            {
                if (ExportAsBase)
                {
                    foreach (var exportType in GetTypes(strategy.ActivationType))
                    {
                        AddStrategyByAs(strategy, exportType, null);
                    }
                }
                else
                {
                    AddStrategyByAs(strategy, strategy.ActivationType, null);
                }
            }
        }