/// <summary>
        /// Derived classes implement this method to calculate if the policy
        /// will provide any handler to the specified member.
        /// </summary>
        /// <param name="member">Member to check.</param>
        /// <returns>true if policy applies to this member, false if not.</returns>
        protected override bool DoesMatch(MethodImplementationInfo member)
        {
            bool matchesInterface = member.InterfaceMethodInfo != null ? attributeMatchRule.Matches(member.InterfaceMethodInfo) : false;
            bool matchesImplementation = attributeMatchRule.Matches(member.ImplementationMethodInfo);

            return matchesInterface | matchesImplementation;
        }
Exemplo n.º 2
0
 private bool DoesNotHaveNoPoliciesAttributeRule(MethodImplementationInfo method)
 {
     bool doesNotHaveRule = true;
     doesNotHaveRule &= method.InterfaceMethodInfo != null ? doesNotHaveNoPoliciesAttributeRule.Matches(method.InterfaceMethodInfo) : true;
     doesNotHaveRule &= doesNotHaveNoPoliciesAttributeRule.Matches(method.ImplementationMethodInfo);
     return doesNotHaveRule;
 }
Exemplo n.º 3
0
        protected override bool DoesMatch(MethodImplementationInfo member)
        {
            Microsoft.Practices.Unity.Utility.Guard.ArgumentNotNull(member, "member");

            bool matchesInterface = member.InterfaceMethodInfo != null && this.ruleSet.Matches(member.InterfaceMethodInfo);
            bool matchesImplementation = this.ruleSet.Matches(member.ImplementationMethodInfo);
            return matchesInterface | matchesImplementation;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Derived classes implement this method to calculate if the policy
        /// will provide any handler to the specified member.
        /// </summary>
        /// <param name="member">Member to check.</param>
        /// <returns>true if policy applies to this member, false if not.</returns>
        protected override bool DoesMatch(MethodImplementationInfo member)
        {
            bool matchesInterface = member.InterfaceMethodInfo != null?attributeMatchRule.Matches(member.InterfaceMethodInfo) : false;

            bool matchesImplementation = attributeMatchRule.Matches(member.ImplementationMethodInfo);

            return(matchesInterface | matchesImplementation);
        }
Exemplo n.º 5
0
        private bool DoesNotHaveNoPoliciesAttributeRule(MethodImplementationInfo method)
        {
            bool doesNotHaveRule = true;

            doesNotHaveRule &= method.InterfaceMethodInfo != null?doesNotHaveNoPoliciesAttributeRule.Matches(method.InterfaceMethodInfo) : true;

            doesNotHaveRule &= doesNotHaveNoPoliciesAttributeRule.Matches(method.ImplementationMethodInfo);
            return(doesNotHaveRule);
        }
        protected override bool DoesMatch(MethodImplementationInfo member)
        {
            Microsoft.Practices.Unity.Utility.Guard.ArgumentNotNull(member, "member");

            bool matchesInterface = member.InterfaceMethodInfo != null?this.attributeMatchRule.Matches(member.InterfaceMethodInfo) : false;

            bool matchesImplementation = this.attributeMatchRule.Matches(member.ImplementationMethodInfo);

            return(matchesInterface | matchesImplementation);
        }
 /// <summary>
 /// Return ordered collection of handlers in order that apply to the given member.
 /// </summary>
 /// <param name="member">Member that may or may not be assigned handlers by this policy.</param>
 /// <param name="container">The <see cref="IUnityContainer"/> to use when creating handlers,
 /// if necessary.</param>
 /// <returns>Collection of handlers (possibly empty) that apply to this member.</returns>
 protected override IEnumerable <ICallHandler> DoGetHandlersFor(MethodImplementationInfo member, IUnityContainer container)
 {
     if (this.Matches(member))
     {
         foreach (string callHandlerName in this.callHandlerNames)
         {
             yield return(container.Resolve <ICallHandler>(callHandlerName));
         }
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Get the pipeline for the given method, creating it if necessary.
        /// </summary>
        /// <param name="method">Method to retrieve the pipeline for.</param>
        /// <param name="handlers">Handlers to initialize the pipeline with</param>
        /// <returns>True if the pipeline has any handlers in it, false if not.</returns>
        public bool InitializePipeline(MethodImplementationInfo method, IEnumerable<ICallHandler> handlers)
        {
            var pipeline = CreatePipeline(method.ImplementationMethodInfo, handlers);
            if(method.InterfaceMethodInfo != null)
            {
                pipelines[HandlerPipelineKey.ForMethod(method.InterfaceMethodInfo)] = pipeline;
            }

            return pipeline.Count > 0;
        }
Exemplo n.º 9
0
 /// <summary>
 /// Return ordered collection of handlers in order that apply to the given member.
 /// </summary>
 /// <param name="member">Member that may or may not be assigned handlers by this policy.</param>
 /// <param name="container">The <see cref="IUnityContainer"/> to use when creating handlers,
 /// if necessary.</param>
 /// <returns>Collection of handlers (possibly empty) that apply to this member.</returns>
 protected override IEnumerable<ICallHandler> DoGetHandlersFor(MethodImplementationInfo member, IUnityContainer container)
 {
     if (this.Matches(member))
     {
         foreach (string callHandlerName in this.callHandlerNames)
         {
             yield return container.Resolve<ICallHandler>(callHandlerName);
         }
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// Gets the policies in the <see cref="PolicySet"/> that do not
 /// apply to the given member.
 /// </summary>
 /// <param name="member">Member to check.</param>
 /// <returns>Collection of policies that do not apply to <paramref name="member"/>.</returns>
 public IEnumerable <InjectionPolicy> GetPoliciesNotFor(MethodImplementationInfo member)
 {
     foreach (InjectionPolicy policy in this)
     {
         if (!policy.Matches(member))
         {
             yield return(policy);
         }
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Get the pipeline for the given method, creating it if necessary.
        /// </summary>
        /// <param name="method">Method to retrieve the pipeline for.</param>
        /// <param name="handlers">Handlers to initialize the pipeline with</param>
        /// <returns>True if the pipeline has any handlers in it, false if not.</returns>
        public bool InitializePipeline(MethodImplementationInfo method, IEnumerable <ICallHandler> handlers)
        {
            var pipeline = CreatePipeline(method.ImplementationMethodInfo, handlers);

            if (method.InterfaceMethodInfo != null)
            {
                pipelines[HandlerPipelineKey.ForMethod(method.InterfaceMethodInfo)] = pipeline;
            }

            return(pipeline.Count > 0);
        }
        /// <summary>
        /// Determines whether the specified <see cref="T:System.Object" /> is equal to the current <see cref="T:System.Object" />.
        /// </summary>
        /// <returns>
        /// true if the specified <see cref="T:System.Object" /> is equal to the current <see cref="T:System.Object" />; otherwise, false.
        /// </returns>
        /// <param name="obj">The <see cref="T:System.Object" /> to compare with the current <see cref="T:System.Object" />. </param>
        /// <exception cref="T:System.NullReferenceException">The <paramref name="obj" /> parameter is null.</exception>
        /// <filterpriority>2</filterpriority>
        public override bool Equals(object obj)
        {
            MethodImplementationInfo other = obj as MethodImplementationInfo;

            if (obj == null || other == null)
            {
                return(false);
            }

            return(this == other);
        }
Exemplo n.º 13
0
        public bool InitializePipeline(MethodImplementationInfo method, IEnumerable<ICallHandler> handlers)
        {
            Microsoft.Practices.Unity.Utility.Guard.ArgumentNotNull(method, "method");

            var pipeline = CreatePipeline(method.ImplementationMethodInfo, handlers);
            if(method.InterfaceMethodInfo != null)
            {
                pipelines[HandlerPipelineKey.ForMethod(method.InterfaceMethodInfo)] = pipeline;
            }

            return pipeline.Count > 0;
        }
        public bool InitializePipeline(MethodImplementationInfo method, IEnumerable <ICallHandler> handlers)
        {
            Microsoft.Practices.Unity.Utility.Guard.ArgumentNotNull(method, "method");

            var pipeline = CreatePipeline(method.ImplementationMethodInfo, handlers);

            if (method.InterfaceMethodInfo != null)
            {
                pipelines[HandlerPipelineKey.ForMethod(method.InterfaceMethodInfo)] = pipeline;
            }

            return(pipeline.Count > 0);
        }
Exemplo n.º 15
0
 /// <summary>
 /// Derived classes implement this method to supply the list of handlers for
 /// this specific member.
 /// </summary>
 /// <param name="member">Member to get handlers for.</param>
 /// <param name="container">The <see cref="IUnityContainer"/> to use when creating handlers,
 /// if necessary.</param>
 /// <returns>Enumerable collection of handlers for this method.</returns>
 protected override IEnumerable<ICallHandler> DoGetHandlersFor(MethodImplementationInfo member, IUnityContainer container)
 {
     if (member.InterfaceMethodInfo != null)
     {
         foreach (HandlerAttribute attr in ReflectionHelper.GetAllAttributes<HandlerAttribute>(member.InterfaceMethodInfo, true))
         {
             yield return attr.CreateHandler(container);
         }
     }
     foreach (HandlerAttribute attr in ReflectionHelper.GetAllAttributes<HandlerAttribute>(member.ImplementationMethodInfo, true))
     {
         yield return attr.CreateHandler(container);
     }
 }
 /// <summary>
 /// Derived classes implement this method to supply the list of handlers for
 /// this specific member.
 /// </summary>
 /// <param name="member">Member to get handlers for.</param>
 /// <param name="container">The <see cref="IUnityContainer"/> to use when creating handlers,
 /// if necessary.</param>
 /// <returns>Enumerable collection of handlers for this method.</returns>
 protected override IEnumerable <ICallHandler> DoGetHandlersFor(MethodImplementationInfo member, IUnityContainer container)
 {
     if (member.InterfaceMethodInfo != null)
     {
         foreach (HandlerAttribute attr in ReflectionHelper.GetAllAttributes <HandlerAttribute>(member.InterfaceMethodInfo, true))
         {
             yield return(attr.CreateHandler(container));
         }
     }
     foreach (HandlerAttribute attr in ReflectionHelper.GetAllAttributes <HandlerAttribute>(member.ImplementationMethodInfo, true))
     {
         yield return(attr.CreateHandler(container));
     }
 }
Exemplo n.º 17
0
 /// <summary>
 /// Returns ordered collection of handlers in order that apply to the given member.
 /// </summary>
 /// <param name="member">Member that may or may not be assigned handlers by this policy.</param>
 /// <param name="container">The <see cref="IUnityContainer"/> to use when creating handlers,
 /// if necessary.</param>
 /// <returns>Collection of handlers (possibly empty) that apply to this member.</returns>
 public virtual IEnumerable <ICallHandler> GetHandlersFor(MethodImplementationInfo member, IUnityContainer container)
 {
     if (DoesNotHaveNoPoliciesAttributeRule(member))
     {
         List <ICallHandler> handlers = new List <ICallHandler>(DoGetHandlersFor(member, container));
         if (handlers.Count > 0)
         {
             foreach (ICallHandler handler in handlers)
             {
                 yield return(handler);
             }
             yield break;
         }
     }
 }
        public void WhenConfiguredContainer_ThenCanResolvePolicy()
        {
            using (var container = new UnityContainer())
            {
                this.policyData.ConfigureContainer(container);

                var policy = container.Resolve<RuleDrivenPolicy>("policy");

                var method = new MethodImplementationInfo(StaticReflection.GetMethodInfo<object>(o => o.ToString()), StaticReflection.GetMethodInfo<object>(o => o.ToString()));

                Assert.AreEqual("policy", policy.Name);
                Assert.IsFalse(policy.Matches(method));
                Assert.AreEqual(0, policy.GetHandlersFor(method, container).Count());
            }
        }
Exemplo n.º 19
0
 /// <summary>
 /// Returns ordered collection of handlers in order that apply to the given member.
 /// </summary>
 /// <param name="member">Member that may or may not be assigned handlers by this policy.</param>
 /// <param name="container">The <see cref="IUnityContainer"/> to use when creating handlers,
 /// if necessary.</param>
 /// <returns>Collection of handlers (possibly empty) that apply to this member.</returns>
 public virtual IEnumerable<ICallHandler> GetHandlersFor(MethodImplementationInfo member, IUnityContainer container)
 {
     if (DoesNotHaveNoPoliciesAttributeRule(member))
     {
         List<ICallHandler> handlers = new List<ICallHandler>(DoGetHandlersFor(member, container));
         if (handlers.Count > 0)
         {
             foreach (ICallHandler handler in handlers)
             {
                 yield return handler;
             }
             yield break;
         }
     }
 }
        public void WhenConfiguredContainer_ThenCanResolvePolicy()
        {
            using (var container = new UnityContainer())
            {
                this.policyData.ConfigureContainer(container);

                var policy = container.Resolve<RuleDrivenPolicy>("policy");

                var method = new MethodImplementationInfo(StaticReflection.GetMethodInfo<object>(o => o.ToString()), StaticReflection.GetMethodInfo<object>(o => o.ToString()));

                Assert.AreEqual("policy", policy.Name);
                Assert.IsTrue(policy.Matches(method));
                Assert.AreEqual(0, policy.GetHandlersFor(method, container).Count());

                Assert.AreNotSame(policy, container.Resolve<RuleDrivenPolicy>("policy"));

                Assert.IsTrue(container.Registrations.Any(r => r.Name == "type-policy" && r.RegisteredType == typeof(IMatchingRule) && r.MappedToType == typeof(TypeMatchingRule)));
            }
        }
Exemplo n.º 21
0
        internal static IEnumerable <ICallHandler> CalculateHandlersFor(
            IEnumerable <InjectionPolicy> policies,
            MethodImplementationInfo member,
            IUnityContainer container)
        {
            List <ICallHandler> ordered    = new List <ICallHandler>();
            List <ICallHandler> nonOrdered = new List <ICallHandler>();

            foreach (InjectionPolicy p in policies)
            {
                foreach (ICallHandler handler in p.GetHandlersFor(member, container))
                {
                    if (handler.Order != 0)
                    {
                        bool inserted = false;
                        // add in order to ordered
                        for (int i = ordered.Count - 1; i >= 0; i--)
                        {
                            if (ordered[i].Order <= handler.Order)
                            {
                                ordered.Insert(i + 1, handler);
                                inserted = true;
                                break;
                            }
                        }
                        if (!inserted)
                        {
                            ordered.Insert(0, handler);
                        }
                    }
                    else
                    {
                        nonOrdered.Add(handler);
                    }
                }
            }
            ordered.AddRange(nonOrdered);
            return(ordered);
        }
Exemplo n.º 22
0
 /// <summary>
 /// Checks if the rules in this policy match the given member info.
 /// </summary>
 /// <param name="member">MemberInfo to check against.</param>
 /// <returns>true if ruleset matches, false if it does not.</returns>
 public bool Matches(MethodImplementationInfo member)
 {
     return(DoesNotHaveNoPoliciesAttributeRule(member) &&
            DoesMatch(member));
 }
Exemplo n.º 23
0
 /// <summary>
 /// Derived classes implement this method to supply the list of handlers for
 /// this specific member.
 /// </summary>
 /// <param name="member">Member to get handlers for.</param>
 /// <param name="container">The <see cref="IUnityContainer"/> to use when creating handlers,
 /// if necessary.</param>
 /// <returns>Enumerable collection of handlers for this method.</returns>
 protected abstract IEnumerable <ICallHandler> DoGetHandlersFor(MethodImplementationInfo member, IUnityContainer container);
Exemplo n.º 24
0
 /// <summary>
 /// Derived classes implement this method to calculate if the policy
 /// will provide any handler to the specified member.
 /// </summary>
 /// <param name="member">Member to check.</param>
 /// <returns>true if policy applies to this member, false if not.</returns>
 protected abstract bool DoesMatch(MethodImplementationInfo member);
Exemplo n.º 25
0
 /// <summary>
 /// Checks if the rules in this policy match the given member info.
 /// </summary>
 /// <param name="member">MemberInfo to check against.</param>
 /// <returns>true if ruleset matches, false if it does not.</returns>
 public bool Matches(MethodImplementationInfo member)
 {
     return DoesNotHaveNoPoliciesAttributeRule(member) &&
         DoesMatch(member);
 }
Exemplo n.º 26
0
 /// <summary>
 /// Derived classes implement this method to supply the list of handlers for
 /// this specific member.
 /// </summary>
 /// <param name="member">Member to get handlers for.</param>
 /// <param name="container">The <see cref="IUnityContainer"/> to use when creating handlers,
 /// if necessary.</param>
 /// <returns>Enumerable collection of handlers for this method.</returns>
 protected abstract IEnumerable<ICallHandler> DoGetHandlersFor(MethodImplementationInfo member, IUnityContainer container);
Exemplo n.º 27
0
 /// <summary>
 /// Derived classes implement this method to calculate if the policy
 /// will provide any handler to the specified member.
 /// </summary>
 /// <param name="member">Member to check.</param>
 /// <returns>true if policy applies to this member, false if not.</returns>
 protected abstract bool DoesMatch(MethodImplementationInfo member);
Exemplo n.º 28
0
 /// <summary>
 /// Gets the handlers that apply to the given member based on all policies in the <see cref="PolicySet"/>.
 /// </summary>
 /// <param name="member">Member to get handlers for.</param>
 /// <param name="container">The <see cref="IUnityContainer"/> to use when creating handlers,
 /// if necessary.</param>
 /// <returns>Collection of call handlers for <paramref name="member"/>.</returns>
 public IEnumerable <ICallHandler> GetHandlersFor(MethodImplementationInfo member, IUnityContainer container)
 {
     return(new List <ICallHandler>(CalculateHandlersFor(this, member, container)));
 }
Exemplo n.º 29
0
 public MethodInfo MethodInfoForPipeline(MethodImplementationInfo methodInfo)
 {
     Guard.ArgumentNotNull(methodInfo, "methodInfo");
     return(methodInfo.ImplementationMethodInfo);
 }