Question

I have been using Ninject 2 for a period and have updated to Ninject 3 to better support SignalR and other frameworks.

The code below used to work fine.

public class AttributeDrivenPlanningStrategy<TAttribute, TInterceptor> : NinjectComponent, IPlanningStrategy
        where TAttribute : Attribute
        where TInterceptor : IInterceptor
    {
        private readonly IAdviceFactory adviceFactory;
        private readonly IAdviceRegistry adviceRegistry;

        public AttributeDrivenPlanningStrategy(IAdviceFactory adviceFactory, IAdviceRegistry adviceRegistry)
        {
            this.adviceFactory = adviceFactory;
            this.adviceRegistry = adviceRegistry;
        }

        public void Execute(IPlan plan)
        {
            var methods = GetCandidateMethods(plan.Type);
            foreach (var method in methods)
            {
                if(!method.HasAttribute<TAttribute>())
                { continue; }

                var advice = adviceFactory.Create(method);
                advice.Callback = request => request.Kernel.Get<TInterceptor>();
                adviceRegistry.Register(advice);

                if (!plan.Has<ProxyDirective>()) 
                { plan.Add(new ProxyDirective()); }
            }
        }


        private static IEnumerable<MethodInfo> GetCandidateMethods(Type type)
        {
            const BindingFlags methodFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
            var methods = type.GetMethods(methodFlags);
            return methods.Where(ShouldIntercept);
        }

        private static bool ShouldIntercept(MethodInfo methodInfo)
        {
            return methodInfo.DeclaringType != typeof (object) &&
                   !methodInfo.IsPrivate &&
                   !methodInfo.IsFinal;
        }
    }

However now it blows up saying that it cannot find IAdviceFactory in the ninject bindings, so has there been any breaking changes in the latest version of the interceptor, as there is next to no documentation on this extension (which I find odd given the amount of AoP floating around these days).

So could anyone point me in the direction of somewhere that will tell me what the issue is?

Was it helpful?

Solution

This was down to me not having the dynamicproxy nuget package for the interceptor installed, as the nuget package for ninject.interception does not contain the other libs as you can choose between linfu and castle based proxies.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top