/// <summary>
        /// Create target info for request
        /// </summary>
        /// <returns></returns>
        public ImmutableLinkedList <InjectionTargetInfo> CreateTargetInfo()
        {
            if (_targetInfoList != null)
            {
                return(_targetInfoList);
            }

            var targetName = "";

            if (Info is ParameterInfo info)
            {
                targetName = info.Name;
            }
            else if (Info is MemberInfo memberInfo)
            {
                targetName = memberInfo.Name;
            }

            var targetInfo =
                new InjectionTargetInfo(Services.AttributeDiscoveryService, InjectedType, RequestingStrategy, Info, targetName, RequestType, ActivationType, false, null, UniqueId);

            _targetInfoList = Parent?.CreateTargetInfo() ?? ImmutableLinkedList <InjectionTargetInfo> .Empty;

            _targetInfoList = _targetInfoList.Add(targetInfo);

            return(_targetInfoList);
        }
Example #2
0
        /// <summary>
        /// Add your own custom activation strategy
        /// </summary>
        /// <param name="activationStrategy">activation strategy</param>
        public void AddActivationStrategy(IActivationStrategy activationStrategy)
        {
            if (activationStrategy == null)
            {
                throw new ArgumentNullException(nameof(activationStrategy));
            }

            // ReSharper disable once CanBeReplacedWithTryCastAndCheckForNull
            if (activationStrategy is ICompiledExportStrategy)
            {
                AddExportStrategy((ICompiledExportStrategy)activationStrategy);
            }
            else if (activationStrategy is ICompiledDecoratorStrategy)
            {
                _decoratorStrategyProviders = _decoratorStrategyProviders.Add(
                    new SimpleDecoratorStrategyProvider((ICompiledDecoratorStrategy)activationStrategy));
            }
            else if (activationStrategy is ICompiledWrapperStrategy)
            {
                _wrapperProviders = _wrapperProviders.Add(new SimpleExportWrapperProvider((ICompiledWrapperStrategy)activationStrategy));
            }
            else
            {
                throw new NotSupportedException($"activation strategy of type {activationStrategy.GetType().Name} is not supported");
            }
        }
Example #3
0
 /// <summary>
 /// Add Filter type filter
 /// </summary>
 /// <param name="filter"></param>
 public virtual void AddFilter(Func <Type, bool> filter)
 {
     if (filter != null)
     {
         _filters = _filters.Add(filter);
     }
 }
Example #4
0
        public void ImmutableLinkedList_ReadOnlyList_IndexException()
        {
            var list = ImmutableLinkedList.Create(5, 10, 15);

            Assert.Throws <ArgumentOutOfRangeException>(() => list[-1]);
            Assert.Throws <ArgumentOutOfRangeException>(() => list[3]);
        }
Example #5
0
        public void ImmutableLinkedList_Multithreaded_Test()
        {
            var writerCount = 4;

            _finalList      = new List <int>();
            _linkedList     = ImmutableLinkedList <int> .Empty;
            _countdownEvent = new CountdownEvent(4);
            _startEvent     = new ManualResetEvent(false);

            var listOfTasks = new List <Task>();

            listOfTasks.Add(Task.Run(() => RemoveFromList()));

            for (var i = 0; i < writerCount; i++)
            {
                var value = i;
                var task  = Task.Run(() => AddRangeToList(value * _addAmount));

                listOfTasks.Add(task);
            }


            _startEvent.Set();

            Task.WaitAll(listOfTasks.ToArray(), 60 * 1000);

            _finalList.Sort();

            Assert.Equal(_finalList.Count, _addAmount * writerCount);

            for (var i = 0; i < (_addAmount * writerCount); i++)
            {
                Assert.Equal(i, _finalList[i]);
            }
        }
Example #6
0
        /// <summary>
        /// Create target info for request
        /// </summary>
        /// <param name="targetInfos">child targets</param>
        /// <returns></returns>
        public ImmutableLinkedList <InjectionTargetInfo> CreateTargetInfo(ImmutableLinkedList <InjectionTargetInfo> targetInfos)
        {
            targetInfos = Parent?.CreateTargetInfo(targetInfos) ?? targetInfos;

            if (_targetInfo != null)
            {
                return(targetInfos.Add(_targetInfo));
            }

            var targetName = "";

            if (Info is ParameterInfo)
            {
                targetName = ((ParameterInfo)Info).Name;
            }
            else if (Info is MemberInfo)
            {
                targetName = ((MemberInfo)Info).Name;
            }

            _targetInfo =
                new InjectionTargetInfo(Services.AttributeDiscoveryService, InjectedType, RequestingStrategy, Info, targetName, RequestType, ActivationType, false, null, UniqueId);

            return(targetInfos.Add(_targetInfo));
        }
Example #7
0
        /// <inheritdoc />
        public IRpcApi ClearAuthorize()
        {
            _authorizations = ImmutableLinkedList <Func <IEndPointMethodConfigurationReadOnly, IEnumerable <IEndPointMethodAuthorization> > > .Empty;

            ClearCurrentApi();

            return(this);
        }
Example #8
0
        /// <inheritdoc />
        public IRpcApi ClearPrefixes()
        {
            _prefixes = ImmutableLinkedList <Func <Type, IEnumerable <string> > > .Empty;

            ClearCurrentApi();

            return(this);
        }
Example #9
0
        public void ImmutableLinkedList_ReadOnlyList()
        {
            var list = ImmutableLinkedList.Create(5, 10, 15);

            Assert.Equal(15, list[0]);
            Assert.Equal(10, list[1]);
            Assert.Equal(5, list[2]);
        }
Example #10
0
        /// <summary>
        /// Add IMemberInjectionSelctor that selects
        /// </summary>
        /// <param name="selector"></param>
        public void AddMemberInjectionSelector(IMemberInjectionSelector selector)
        {
            if (selector == null)
            {
                throw new ArgumentNullException(nameof(selector));
            }

            _globalSelectors = _globalSelectors.Add(selector);
        }
Example #11
0
        /// <summary>
        /// Add injection inspector that will be called to inspect all exports, wrappers and decorators (apply cross cutting configuration with an inspector)
        /// </summary>
        /// <param name="inspector">inspector</param>
        public void AddInspector(IActivationStrategyInspector inspector)
        {
            if (inspector == null)
            {
                throw new ArgumentNullException(nameof(inspector));
            }

            _inspectors = _inspectors.Add(inspector);
        }
Example #12
0
        /// <summary>
        /// Add IInjectionValueProvider allowing the developer to override the normal behavior for creating an injection value
        /// </summary>
        /// <param name="provider"></param>
        public void AddInjectionValueProvider(IInjectionValueProvider provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            _valueProviders = _valueProviders.Add(provider);
        }
Example #13
0
        /// <summary>
        /// Add missing export strategy provider
        /// </summary>
        /// <param name="provider"></param>
        public void AddMissingExportStrategyProvider(IMissingExportStrategyProvider provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            _missingExportStrategyProviders = _missingExportStrategyProviders.Add(provider);
        }
Example #14
0
 public SearchState(bool invert, byte rotation, ImmutableCoordinateCube cube, ImmutableLinkedList <Move> movesSoFar, bool deepening)
 {
     Invert              = invert;
     Rotation            = rotation;
     Cube                = cube;
     MovesSoFar          = movesSoFar;
     Deepening           = deepening;
     SearchStatePriority = GetSearchStatePriority(this);
 }
Example #15
0
        public void ImmutableLinkedList_Contains()
        {
            var list = ImmutableLinkedList.Create(5, 10, 15);

            Assert.True(list.Contains(5));
            Assert.True(list.Contains(10));
            Assert.True(list.Contains(15));
            Assert.False(list.Contains(0));
        }
Example #16
0
        /// <summary>
        /// Add strategy inspector
        /// </summary>
        /// <param name="inspector">inspector</param>
        public void AddInspector(IActivationStrategyInspector inspector)
        {
            ImmutableLinkedList.ThreadSafeAdd(ref Inspectors, inspector);

            foreach (var strategy in GetAllStrategies())
            {
                inspector.Inspect(strategy);
            }
        }
Example #17
0
        /// <summary>
        /// Add a secondary strategy for this export strategy
        /// </summary>
        /// <param name="secondaryStrategy">new secondary strategy</param>
        public void AddSecondaryStrategy(ICompiledExportStrategy secondaryStrategy)
        {
            if (secondaryStrategy == null)
            {
                throw new ArgumentNullException(nameof(secondaryStrategy));
            }

            _secondaryStrategies = _secondaryStrategies.Add(secondaryStrategy);
        }
        /// <summary>
        /// add method injection to list
        /// </summary>
        /// <param name="methodInjection"></param>
        public void MethodInjection(MethodInjectionInfo methodInjection)
        {
            if (MethodInjectionList != ImmutableLinkedList <MethodInjectionInfo> .Empty &&
                MethodInjectionList.Any(m => Equals(m.Method, methodInjection.Method)))
            {
                return;
            }

            MethodInjectionList = MethodInjectionList.Add(methodInjection);
        }
Example #19
0
        /// <summary>
        /// Get attributes from MethodInfo, PropertyInfo, ParameterInfo, and FieldInfo
        /// </summary>
        /// <param name="value">MethodInfo, PropertyInfo, ParameterInfo, and FieldInfo</param>
        /// <returns>attributes</returns>
        public IEnumerable <Attribute> GetAttributes(object value)
        {
            if (value == null)
            {
                return(ImmutableLinkedList <Attribute> .Empty);
            }

            var values = _knownValues.GetValueOrDefault(value);

            if (values != null)
            {
                return(values);
            }

            Attribute[] attributes;

            var type = value as Type;

            if (type != null)
            {
                attributes = type.GetTypeInfo().GetCustomAttributes()?.ToArray();
            }
            else
            {
                var parameterInfo = value as ParameterInfo;

                if (parameterInfo != null)
                {
                    attributes = parameterInfo.GetCustomAttributes()?.ToArray();
                }
                else
                {
                    var memberInfo = value as MemberInfo;

                    if (memberInfo != null)
                    {
                        attributes = memberInfo.GetCustomAttributes <Attribute>()?.ToArray();
                    }
                    else
                    {
                        throw new NotSupportedException(
                                  $"Getting attributes on type {value.GetType().Name} is not supported");
                    }
                }
            }

            if (attributes == null || attributes.Length == 0)
            {
                return(ImmutableLinkedList <Attribute> .Empty);
            }

            var list = ImmutableLinkedList.From(attributes);

            return(ImmutableHashTree.ThreadSafeAdd(ref _knownValues, value, list));
        }
        /// <summary>
        /// Export all types based on speficied type by Type
        /// </summary>
        /// <param name="baseType">base type to export</param>
        /// <returns>configuration object</returns>
        public IExportTypeSetConfiguration BasedOn(Type baseType)
        {
            if (baseType == null)
            {
                throw new ArgumentNullException(nameof(baseType));
            }

            _basedOnTypes = _basedOnTypes.Add(baseType);

            return(this);
        }
        /// <summary>
        /// Export by name
        /// </summary>
        /// <param name="nameFunc"></param>
        /// <returns></returns>
        public IExportTypeSetConfiguration ByName(Func <Type, IEnumerable <string> > nameFunc = null)
        {
            if (nameFunc == null)
            {
                nameFunc = type => new[] { type.Name };
            }

            _byName = _byName.Add(nameFunc);

            return(this);
        }
        /// <summary>
        /// Exports by a set of types
        /// </summary>
        /// <param name="typeDelegate"></param>
        /// <returns></returns>
        public IExportTypeSetConfiguration ByTypes(Func <Type, IEnumerable <Type> > typeDelegate)
        {
            if (typeDelegate == null)
            {
                throw new ArgumentNullException(nameof(typeDelegate));
            }

            _byTypes = _byTypes.Add(typeDelegate);

            return(this);
        }
        /// <summary>
        /// Export a type by a set of keyed types
        /// </summary>
        /// <param name="keyedDelegate">keyed types</param>
        /// <returns></returns>
        public IExportTypeSetConfiguration ByKeyedTypes(Func <Type, IEnumerable <Tuple <Type, object> > > keyedDelegate)
        {
            if (keyedDelegate == null)
            {
                throw new ArgumentNullException(nameof(keyedDelegate));
            }

            _byKeyedType = _byKeyedType.Add(keyedDelegate);

            return(this);
        }
        /// <summary>
        /// Exclude a type from being used
        /// </summary>
        /// <param name="exclude">exclude delegate</param>
        /// <returns>configuration object</returns>
        public IExportTypeSetConfiguration Exclude(Func <Type, bool> exclude)
        {
            if (exclude == null)
            {
                throw new ArgumentNullException(nameof(exclude));
            }

            _excludeFuncs = _excludeFuncs.Add(exclude);

            return(this);
        }
        /// <summary>
        /// Add inspector for type set
        /// </summary>
        /// <param name="inspector"></param>
        /// <returns></returns>
        public IExportTypeSetConfiguration WithInspector(IActivationStrategyInspector inspector)
        {
            if (inspector == null)
            {
                throw new ArgumentNullException(nameof(inspector));
            }

            _inspectors = _inspectors.Add(inspector);

            return(this);
        }
        /// <summary>
        /// Add conditions for export
        /// </summary>
        /// <param name="conditionFunc"></param>
        /// <returns></returns>
        public IExportTypeSetConfiguration AndCondition(Func <Type, IEnumerable <ICompiledCondition> > conditionFunc)
        {
            if (conditionFunc == null)
            {
                throw new ArgumentNullException(nameof(conditionFunc));
            }

            _conditions = _conditions.Add(conditionFunc);

            return(this);
        }
Example #27
0
        public void ImmutableLinkedList_Create()
        {
            var list = ImmutableLinkedList.Create(5, 10, 15);

            var newList = new List <int>(list);

            Assert.Equal(3, newList.Count);
            Assert.Contains(5, newList);
            Assert.Contains(10, newList);
            Assert.Contains(15, newList);
        }
Example #28
0
        public void ImmutableLinkedList_From()
        {
            var list = ImmutableLinkedList.From(new[] { 5, 10, 15 });

            var newList = new List <int>(list);

            Assert.Equal(3, newList.Count);
            Assert.Contains(5, newList);
            Assert.Contains(10, newList);
            Assert.Contains(15, newList);
        }
Example #29
0
        public void ImmutableLinkedList_ThreadSafeAddRange()
        {
            var list = ImmutableLinkedList <int> .Empty;

            ImmutableLinkedList.ThreadSafeAddRange(ref list, new[] { 5, 10, 15 });

            Assert.Equal(3, list.Count);
            Assert.Contains(5, list);
            Assert.Contains(10, list);
            Assert.Contains(15, list);
        }
Example #30
0
        /// <summary>
        /// Use func for providing authorization
        /// </summary>
        /// <param name="authorizationFunc"></param>
        /// <returns></returns>
        public ITypeSetExposureConfiguration Authorize(Func <Type, IEnumerable <IMethodAuthorization> > authorizationFunc)
        {
            if (authorizationFunc == null)
            {
                throw new ArgumentNullException(nameof(authorizationFunc));
            }

            _authorizations = _authorizations.Add(authorizationFunc);

            return(this);
        }