示例#1
0
        /// <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);
        }
示例#2
0
        /// <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);
        }
示例#3
0
        /// <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);
        }
示例#4
0
        /// <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);
        }
示例#5
0
        /// <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);
        }
示例#6
0
        /// <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);
        }
示例#7
0
        /// <summary>
        /// Export all classes by interface or that match a set of interfaces
        /// </summary>
        /// <param name="whereClause">where clause to test if the interface should be used for exporting</param>
        /// <returns>configuration object</returns>
        public IExportTypeSetConfiguration ByInterfaces(Func <Type, bool> whereClause = null)
        {
            if (whereClause == null)
            {
                whereClause = type => true;
            }

            _byInterfaces = _byInterfaces.Add(whereClause);

            return(this);
        }
示例#8
0
        /// <summary>
        /// Authorize exposures
        /// </summary>
        /// <param name="role"></param>
        /// <param name="policy"></param>
        /// <returns></returns>
        public ITypeSetExposureConfiguration Authorize(string role = null, string policy = null)
        {
            IMethodAuthorization authorize = null;

            if (role != null)
            {
                authorize = new UserRoleAuthorization(role);
            }
            else if (policy != null)
            {
                authorize = new UserPolicyAuthorization(policy);
            }
            else
            {
                authorize = new UserAuthenticatedAuthorization();
            }

            _authorizations = _authorizations.Add(t => new[] { authorize });

            return(this);
        }
示例#9
0
        /// <summary>
        /// Set default Authorize
        /// </summary>
        /// <param name="role"></param>
        /// <param name="policy"></param>
        /// <returns></returns>
        public IApiConfiguration Authorize(string role = null, string policy = null)
        {
            IMethodAuthorization authorization = null;

            if (!string.IsNullOrEmpty(role))
            {
                authorization = new UserRoleAuthorization(role);
            }
            else if (!string.IsNullOrEmpty(policy))
            {
                authorization = new UserPolicyAuthorization(policy);
            }
            else
            {
                authorization = new UserAuthenticatedAuthorization();
            }
            var array = new[] { authorization };

            _authorizations = _authorizations.Add(t => array);

            return(this);
        }
示例#10
0
        /// <summary>
        /// Add extra expression to result
        /// </summary>
        /// <param name="expression">expression for delegate</param>
        /// <param name="insertBeginning"></param>
        public void AddExtraExpression(Expression expression, bool insertBeginning = false)
        {
            if (insertBeginning)
            {
                var expressions = _extraExpressions;

                _extraExpressions = ImmutableLinkedList <Expression> .Empty.Add(expression);

                expressions.Visit(e => _extraExpressions = _extraExpressions.Add(e), startAtEnd: true);
            }
            else
            {
                _extraExpressions = _extraExpressions.Add(expression);
            }
        }
示例#11
0
        private void ProcessInjectionDependencies()
        {
            foreach (var strategy in _injectionScope.StrategyCollectionContainer.GetAllStrategies())
            {
                try
                {
                    var dependencies = strategy.GetDependencies();

                    _missingDependencies = _missingDependencies.AddRange(dependencies.Where(d => d.IsSatisfied == false));
                }
                catch (Exception exp)
                {
                    _containerExceptions = _containerExceptions.Add(exp.Message);
                }
            }
        }
        /// <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;

            var targetName = "";

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

            return(targetInfos.Add(new InjectionTargetInfo(Services.AttributeDiscoveryService, InjectedType, RequestingStrategy, Info, targetName, RequestType, ActivationType, false, null, UniqueId)));
        }
        public IExposureConfiguration Authorize(string role = null, string policy = null)
        {
            IEndPointMethodAuthorization authorization = null;

            if (!string.IsNullOrEmpty(policy))
            {
                authorization = new UserHasPolicy(policy);
            }
            else if (!string.IsNullOrEmpty(role))
            {
                authorization = new UserHasRole(role);
            }
            else
            {
                authorization = new UserIsAuthorized();
            }

            _authorizations = _authorizations.Add(authorization);

            return(this);
        }
示例#14
0
 /// <summary>
 /// Add a secondary strategy for this export strategy
 /// </summary>
 /// <param name="secondaryStrategy">new secondary strategy</param>
 public void AddSecondaryStrategy(ICompiledExportStrategy secondaryStrategy)
 {
     _secondaryStrategies = _secondaryStrategies.Add(secondaryStrategy);
 }
示例#15
0
        /// <inheritdoc />
        public IRpcApi Prefix(Func <Type, IEnumerable <string> > prefixFunc)
        {
            _prefixes = _prefixes.Add(prefixFunc);

            return(this);
        }
示例#16
0
 /// <summary>
 /// Add a information for injected method parameters
 /// </summary>
 /// <param name="methodParameterInfo"></param>
 public void MethodParameterInfo(MethodParameterInfo methodParameterInfo)
 {
     _parameterInfo = _parameterInfo.Add(methodParameterInfo);
 }
示例#17
0
 /// <summary>
 /// Add filter to filter group
 /// </summary>
 /// <param name="filter"></param>
 public void Add(Func <T, bool> filter)
 {
     _typeFilters = _typeFilters.Add(filter);
 }
 /// <summary>
 /// Export as name
 /// </summary>
 /// <param name="name"></param>
 public void AddExportAsName(string name)
 {
     _exportAsName = _exportAsName.Add(name);
 }
        /// <inheritdoc />
        public ITypeSetExposureConfiguration As(Func <Type, IEnumerable <string> > nameFunc)
        {
            AsFuncs = AsFuncs.Add(nameFunc);

            return(this);
        }
 /// <summary>
 /// Export as a specific type
 /// </summary>
 /// <param name="exportType">type to export as</param>
 public void AddExportAs(Type exportType)
 {
     _exportAs = _exportAs.Add(exportType);
 }
 /// <summary>
 /// Export as keyed type
 /// </summary>
 /// <param name="exportType">type to export as</param>
 /// <param name="key">export key</param>
 public void AddExportAsKeyed(Type exportType, object key)
 {
     _exportAsKeyed = _exportAsKeyed.Add(new KeyValuePair <Type, object>(exportType, key));
 }
示例#22
0
        /// <inheritdoc />
        public IRpcApi Authorize(Func <IEndPointMethodConfigurationReadOnly, IEnumerable <IEndPointMethodAuthorization> > authorizations)
        {
            _authorizations = _authorizations.Add(authorizations);

            return(this);
        }
示例#23
0
        /// <inheritdoc />
        public IRpcApi MethodFilter(Func <MethodInfo, bool> methodFilter)
        {
            _methodFilters = _methodFilters.Add(methodFilter);

            return(this);
        }
 /// <summary>
 /// add method injection to list
 /// </summary>
 /// <param name="methodInjection"></param>
 public void MethodInjection(MethodInjectionInfo methodInjection)
 {
     MethodInjectionList = MethodInjectionList.Add(methodInjection);
 }
        /// <inheritdoc />
        public ITypeSetExposureConfiguration Authorize(Func <Type, IEnumerable <IEndPointMethodAuthorization> > authorizationFunc)
        {
            AuthorizeFuncs = AuthorizeFuncs.Add(authorizationFunc);

            return(this);
        }
示例#26
0
 /// <summary>
 /// Add missing dependency expression provider
 /// </summary>
 /// <param name="provider"></param>
 public void AddMissingDependencyExpressionProvider(IMissingDependencyExpressionProvider provider)
 {
     _missingDependencyExpressionProviders = _missingDependencyExpressionProviders.Add(provider);
 }
示例#27
0
 /// <summary>
 /// Add extra parameter for expression
 /// </summary>
 /// <param name="parameter">parameter to declare</param>
 public void AddExtraParameter(ParameterExpression parameter)
 {
     _parameterExpressions = _parameterExpressions.Add(parameter);
 }
示例#28
0
        /// <inheritdoc />
        public IRpcApi Header(string header, string value)
        {
            _responseHeaders = _responseHeaders.Add(new ResponseHeader.ResponseHeader(header, value));

            return(this);
        }
示例#29
0
        /// <inheritdoc />
        public IRpcApi ApplyFilter(Func <IEndPointMethodConfigurationReadOnly, Func <RequestExecutionContext, IRequestFilter> > filterFunc)
        {
            _filters = _filters.Add(filterFunc);

            return(this);
        }
 /// <summary>
 /// Add member injection selector to configuration
 /// </summary>
 /// <param name="selector"></param>
 public void MemberInjectionSelector(IMemberInjectionSelector selector)
 {
     MemberInjectorList = MemberInjectorList.Add(selector);
 }