/// <summary> /// Contributes to the specified plan. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute( IPlan plan ) { EventInfo[] events = plan.Type.GetEvents( BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance ); foreach ( EventInfo evt in events ) { IEnumerable<PublishAttribute> attributes = evt.GetAttributes<PublishAttribute>(); foreach ( PublishAttribute attribute in attributes ) { plan.Add( new PublicationDirective( attribute.Channel, evt ) ); } } MethodInfo[] methods = plan.Type.GetMethods( BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance ); foreach ( MethodInfo method in methods ) { IEnumerable<SubscribeAttribute> attributes = method.GetAttributes<SubscribeAttribute>(); foreach ( SubscribeAttribute attribute in attributes ) { MethodInjector injector = InjectorFactory.Create( method ); plan.Add( new SubscriptionDirective( attribute.Channel, injector, attribute.Thread ) ); } } }
/// <summary> /// Contributes to the specified plan. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { EventInfo[] events = plan.Type.GetEvents(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); foreach (EventInfo evt in events) { IEnumerable <PublishAttribute> attributes = evt.GetAttributes <PublishAttribute>(); foreach (PublishAttribute attribute in attributes) { plan.Add(new PublicationDirective(attribute.Channel, evt)); } } MethodInfo[] methods = plan.Type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); foreach (MethodInfo method in methods) { IEnumerable <SubscribeAttribute> attributes = method.GetAttributes <SubscribeAttribute>(); foreach (SubscribeAttribute attribute in attributes) { MethodInjector injector = InjectorFactory.Create(method); plan.Add(new SubscriptionDirective(attribute.Channel, injector, attribute.Thread)); } } }
/// <summary> /// Contributes to the specified plan. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute( IPlan plan ) { EventInfo[] events = plan.Type.GetEvents( DefaultBindingFlags ); foreach ( EventInfo evt in events ) { IEnumerable<PublishAttribute> attributes = evt.GetAttributes<PublishAttribute>(); foreach ( PublishAttribute attribute in attributes ) { plan.Add( new PublicationDirective( attribute.Channel, evt ) ); } } MethodInfo[] methods = plan.Type.GetMethods( DefaultBindingFlags ); foreach ( MethodInfo method in methods ) { IEnumerable<SubscribeAttribute> attributes = method.GetAttributes<SubscribeAttribute>(); foreach ( SubscribeAttribute attribute in attributes ) { plan.Add( new SubscriptionDirective( attribute.Channel, method ) ); } } }
/// <summary> /// Contributes to the specified plan. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { EventInfo[] events = plan.Type.GetEvents(DefaultBindingFlags); foreach (EventInfo evt in events) { IEnumerable <PublishAttribute> attributes = evt.GetAttributes <PublishAttribute>(); foreach (PublishAttribute attribute in attributes) { plan.Add(new PublicationDirective(attribute.Channel, evt)); } } MethodInfo[] methods = plan.Type.GetMethods(DefaultBindingFlags); foreach (MethodInfo method in methods) { IEnumerable <SubscribeAttribute> attributes = method.GetAttributes <SubscribeAttribute>(); foreach (SubscribeAttribute attribute in attributes) { plan.Add(new SubscriptionDirective(attribute.Channel, method, attribute.Thread)); } } }
/// <summary> /// Contributes to the specified plan. /// </summary> /// <param name="plan">The plan that is being generated.</param> public override void Execute(IPlan plan) { if (!typeof(IAutoNotifyPropertyChanged).IsAssignableFrom(plan.Type)) { return; } IEnumerable <MethodInfo> candidates = GetCandidateMethods(plan.Type); RegisterClassInterceptors(plan.Type, plan, candidates); foreach (MethodInfo method in candidates) { PropertyInfo property = method.GetPropertyFromMethod(method.DeclaringType); NotifyOfChangesAttribute[] attributes = property.GetAllAttributes <NotifyOfChangesAttribute>(); if (attributes.Length == 0) { continue; } RegisterMethodInterceptors(plan.Type, method, attributes); // Indicate that instances of the type should be proxied. if (!plan.Has <ProxyDirective>()) { plan.Add(new ProxyDirective()); } } }
/// <summary> /// Contributes to the specified plan. /// </summary> /// <param name="plan">The plan that is being generated.</param> public override void Execute( IPlan plan ) { if ( !typeof (IAutoNotifyPropertyChanged).IsAssignableFrom( plan.Type ) ) { return; } IEnumerable<MethodInfo> candidates = GetCandidateMethods( plan.Type ); RegisterClassInterceptors( plan.Type, plan, candidates ); foreach ( MethodInfo method in candidates ) { PropertyInfo property = method.GetPropertyFromMethod( method.DeclaringType ); NotifyOfChangesAttribute[] attributes = property.GetAllAttributes<NotifyOfChangesAttribute>(); if ( attributes.Length == 0 ) { continue; } RegisterMethodInterceptors( plan.Type, method, attributes ); // Indicate that instances of the type should be proxied. if ( !plan.Has<ProxyDirective>() ) { plan.Add( new ProxyDirective() ); } } }
/// <summary> /// Adds a <see cref="MethodInjectionDirective"/> to the plan for each method /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { foreach (MethodInfo method in Selector.SelectMethodsForInjection(plan.Type)) { plan.Add(new MethodInjectionDirective(method, InjectorFactory.Create(method))); } }
/// <summary> /// Adds a <see cref="MethodInjectionDirective"/> to the plan for each method /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { foreach (MethodInfo method in this.Selector.SelectMethodsForInjection(plan.Type)) { plan.Add(new MethodInjectionDirective(method, this.InjectorFactory.Create(method))); } }
/// <summary> /// Contributes to the specified plan. /// </summary> /// <param name="plan">The plan that is being generated.</param> public virtual void Execute(IPlan plan) { IEnumerable <MethodInfo> candidates = GetCandidateMethods(plan.Type); RegisterClassInterceptors(plan.Type, plan, candidates); foreach (MethodInfo method in candidates) { PropertyInfo property = method.GetPropertyFromMethod(plan.Type); ICustomAttributeProvider provider = (ICustomAttributeProvider)property ?? method; InterceptAttribute[] attributes = provider.GetAllAttributes <InterceptAttribute>(); if (attributes.Length == 0) { continue; } RegisterMethodInterceptors(plan.Type, method, attributes); // Indicate that instances of the type should be proxied. if (!plan.Has <ProxyDirective>()) { plan.Add(new ProxyDirective()); } } }
/// <summary> /// Adds a <see cref="PropertyInjectionDirective"/> to the plan for each property /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { foreach (PropertyInfo property in this.Selector.SelectPropertiesForInjection(plan.Type)) { plan.Add(new PropertyInjectionDirective(property, this.InjectorFactory.Create(property))); } }
/// <summary> /// Adds a <see cref="MethodInjectionDirective"/> to the plan for each method /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { Ensure.ArgumentNotNull(plan, "plan"); foreach (MethodInfo method in Selector.SelectMethodsForInjection(plan.Type)) plan.Add(new MethodInjectionDirective(method, InjectorFactory.Create(method))); }
/// <summary> /// Execute the plan strategy /// </summary> /// <param name="plan">Plan</param> public void Execute(IPlan plan) { var manager = this._kernel.Get<IObjectCacheManager>(); if (!manager.HasCachedMethods(plan.Type)) { return; } var methods = manager.GetCachedMethods(plan.Type); foreach (var method in methods) { var advice = this._adviceFactory.Create(method); var cache = manager.GetCache(plan.Type, method); var methodCache = typeof (MethodCache); var cacheMethod = (IInterceptor)Activator.CreateInstance(methodCache, cache); advice.Callback = request => cacheMethod; this._adviceRegistry.Register(advice); if (!plan.Has<ProxyDirective>()) { plan.Add(new ProxyDirective()); } } }
/// <summary> /// Adds a <see cref="PropertyInjectionDirective"/> to the plan for each property /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { Ensure.ArgumentNotNull(plan, "plan"); foreach (PropertyInfo property in Selector.SelectPropertiesForInjection(plan.Type)) plan.Add(new PropertyInjectionDirective(property, InjectorFactory.Create(property))); }
/// <summary> /// Execute the plan strategy /// </summary> /// <param name="plan">Plan</param> public void Execute(IPlan plan) { var manager = this._kernel.Get <IObjectCacheManager>(); if (!manager.HasCachedMethods(plan.Type)) { return; } var methods = manager.GetCachedMethods(plan.Type); foreach (var method in methods) { var advice = this._adviceFactory.Create(method); var cache = manager.GetCache(plan.Type, method); var methodCache = typeof(MethodCache); var cacheMethod = (IInterceptor)Activator.CreateInstance(methodCache, cache); advice.Callback = request => cacheMethod; this._adviceRegistry.Register(advice); if (!plan.Has <ProxyDirective>()) { plan.Add(new ProxyDirective()); } } }
/// <summary> /// Registers static interceptors defined by attributes on the class for all candidate /// methods on the class, execept those decorated with a <see cref="DoNotInterceptAttribute"/>. /// </summary> /// <param name="type">The type whose activation plan is being manipulated.</param> /// <param name="plan">The activation plan that is being manipulated.</param> /// <param name="candidates">The candidate methods to intercept.</param> protected virtual void RegisterClassInterceptors(Type type, IPlan plan, IEnumerable <MethodInfo> candidates) { InterceptAttribute[] attributes = type.GetAllAttributes <InterceptAttribute>(); if (attributes.Length == 0) { return; } foreach (MethodInfo method in candidates) { PropertyInfo property = method.GetPropertyFromMethod(type); ICustomAttributeProvider provider = (ICustomAttributeProvider)property ?? method; if (!provider.HasAttribute <DoNotInterceptAttribute>()) { RegisterMethodInterceptors(type, method, attributes); } } // Indicate that instances of the type should be proxied. if (!plan.Has <ProxyDirective>()) { plan.Add(new ProxyDirective()); } }
/// <summary> /// Adds a <see cref="MethodInjectionDirective"/> to the plan for each method /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { Ensure.ArgumentNotNull(plan, "plan"); foreach (MethodInfo method in this.Selector.SelectMethodsForInjection(plan.Type)) { plan.Add(new MethodInjectionDirective(method, this.InjectorFactory.Create(method))); } }
/// <summary> /// Adds a <see cref="PropertyInjectionDirective"/> to the plan for each property /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { Ensure.ArgumentNotNull(plan, "plan"); foreach (PropertyInfo property in Selector.SelectPropertiesForInjection(plan.Type)) { plan.Add(new PropertyInjectionDirective(property, InjectorFactory.Create(property))); } }
/// <summary> /// Adds a <see cref="ConstructorInjectionDirective"/> to the plan for the constructor /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { Ensure.ArgumentNotNull(plan, "plan"); ConstructorInfo constructor = Selector.SelectConstructor(plan.Type); if (constructor != null) plan.Add(new ConstructorInjectionDirective(constructor, InjectorFactory.Create(constructor))); }
/// <summary> /// Adds a serial of <see cref="ConstructorInjectionDirective"/>s to the plan for the constructors /// that could be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> /// <exception cref="ArgumentNullException"><paramref name="plan"/> is <see langword="null"/>.</exception> public void Execute(IPlan plan) { Ensure.ArgumentNotNull(plan, nameof(plan)); var constructors = this.selector.SelectConstructorsForInjection(plan.Type); foreach (var constructor in constructors) { var directive = new ConstructorInjectionDirective(constructor, this.injectorFactory.Create(constructor)); plan.Add(directive); } }
/// <summary> /// Adds a <see cref="ConstructorInjectionDirective"/> to the plan for the constructor /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { Ensure.ArgumentNotNull(plan, "plan"); IEnumerable<ConstructorInfo> constructors = Selector.SelectConstructorsForInjection(plan.Type); if(constructors == null) return; foreach(ConstructorInfo constructor in constructors) { plan.Add(new ConstructorInjectionDirective(constructor, InjectorFactory.Create(constructor))); } }
/// <summary> /// Adds a <see cref="ConstructorInjectionDirective" /> to the plan for the constructor /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { Ensure.ArgumentNotNull(plan, "plan"); var constructors = Selector.SelectConstructorsForInjection(plan.Type); if (constructors == null) return; foreach (var constructor in constructors) { plan.Add(new ConstructorInjectionDirective(constructor, InjectorFactory.Create(constructor))); } }
/// <summary> /// Adds a <see cref="PropertyDirective"/> to the plan for each property /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { if (plan == null) { throw new ArgumentNullException(nameof(plan)); } var properties = Selector.SelectPropertiesForInjection(plan.Type); if (properties != null) { foreach (var property in properties) { plan.Add(new PropertyDirective(property, InjectorFactory.Create(property))); } } }
/// <summary> /// Adds a <see cref="MethodDirective"/> to the plan for each method /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { if (plan == null) { throw new ArgumentNullException(nameof(plan)); } var methods = Selector.SelectMethodsForInjection(plan.Type); if (methods != null) { foreach (var method in methods) { plan.Add(new MethodDirective(method, InjectorFactory.Create(method))); } } }
/// <summary> /// Adds a <see cref="ConstructorInjectionDirective"/> to the plan for the constructor /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { IEnumerable<ConstructorInfo> constructors = Selector.SelectConstructorsForInjection(plan.Type); if(constructors == null) return; foreach(ConstructorInfo constructor in constructors) { var hasInjectAttribute = constructor.HasAttribute(Settings.InjectAttribute); var directive = new ConstructorInjectionDirective(constructor, InjectorFactory.Create(constructor)) { HasInjectAttribute = hasInjectAttribute }; plan.Add(directive); } }
/// <summary> /// Adds a <see cref="ConstructorInjectionDirective"/> to the plan for the constructor /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { Ensure.ArgumentNotNull(plan, "plan"); IEnumerable<ConstructorInfo> constructors = Selector.SelectConstructorsForInjection(plan.Type); if(constructors == null) return; foreach(ConstructorInfo constructor in constructors) { var hasInjectAttribute = constructor.HasAttribute(Settings.InjectAttribute); plan.Add( new ConstructorInjectionDirective(constructor, InjectorFactory.Create(constructor)) { HasInjectAttribute = hasInjectAttribute }); } }
/// <summary> /// Adds a <see cref="ConstructorDirective"/> to the plan for the constructor /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { if (plan == null) { throw new ArgumentNullException(nameof(plan)); } var constructors = Selector.SelectConstructorsForInjection(plan.Type); if (constructors != null) { foreach (var constructor in constructors) { plan.Add(new ConstructorDirective(constructor, InjectorFactory.Create(constructor)) { HasInjectAttribute = constructor.IsDefined(Settings.InjectAttribute, false) }); } } }
/// <summary> /// Adds a <see cref="ConstructorInjectionDirective"/> to the plan for the constructor /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { var constructors = this.Selector.SelectConstructorsForInjection(plan.Type); if (constructors == null) { return; } foreach (ConstructorInfo constructor in constructors) { var hasInjectAttribute = constructor.HasAttribute(this.Settings.InjectAttribute); var directive = new ConstructorInjectionDirective(constructor, this.InjectorFactory.Create(constructor)) { HasInjectAttribute = hasInjectAttribute }; plan.Add(directive); } }
/// <summary> /// Adds a <see cref="ConstructorInjectionDirective"/> to the plan for the constructor /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { Ensure.ArgumentNotNull(plan, "plan"); IEnumerable <ConstructorInfo> constructors = Selector.SelectConstructorsForInjection(plan.Type); if (constructors == null) { return; } foreach (ConstructorInfo constructor in constructors) { var hasInjectAttribute = constructor.HasAttribute(Settings.InjectAttribute); plan.Add( new ConstructorInjectionDirective(constructor, InjectorFactory.Create(constructor)) { HasInjectAttribute = hasInjectAttribute }); } }
public void Execute(IPlan plan) { var methods = GetCandidateMethods(plan.Type); foreach (var method in methods) { var attributes = method.GetCustomAttributes( typeof(TAttribute), true) as TAttribute[]; if (attributes.Length == 0) { continue; } var advice = adviceFactory.Create(method); advice.Callback = request => (TInterceptor)request.Kernel.GetService(typeof(TInterceptor)); adviceRegistry.Register(advice); if (!plan.Has <ProxyDirective>()) { plan.Add(new ProxyDirective()); } } }
/// <summary> /// Registers static interceptors defined by attributes on the class for all candidate /// methods on the class, execept those decorated with a <see cref="DoNotInterceptAttribute"/>. /// </summary> /// <param name="type">The type whose activation plan is being manipulated.</param> /// <param name="plan">The activation plan that is being manipulated.</param> /// <param name="candidates">The candidate methods to intercept.</param> protected override void RegisterClassInterceptors(Type type, IPlan plan, IEnumerable <MethodInfo> candidates) { NotifyOfChangesAttribute[] attributes = type.GetAllAttributes <NotifyOfChangesAttribute>(); if (attributes.Length == 0) { return; } foreach (MethodInfo method in candidates) { if (!method.HasAttribute <DoNotNotifyOfChangesAttribute>()) { RegisterMethodInterceptors(type, method, attributes); } } // Indicate that instances of the type should be proxied. if (!plan.Has <ProxyDirective>()) { plan.Add(new ProxyDirective()); } }
/// <summary> /// Contributes to the specified plan. /// </summary> /// <param name="plan">The plan that is being generated.</param> public override void Execute(IPlan plan) { if (!MethodInterceptorRegistry.Contains(plan.Type)) { return; } MethodInterceptorCollection methodInterceptors = MethodInterceptorRegistry.GetMethodInterceptors(plan.Type); Dictionary <MethodInfo, List <IInterceptor> > .KeyCollection methods = methodInterceptors.Keys; if (methods.Count == 0) { return; } foreach (MethodInfo method in methods) { for (int order = 0; order < methodInterceptors[method].Count; order++) { IInterceptor interceptor = methodInterceptors[method][order]; RegisterMethodInterceptors(plan.Type, method, new[] { new InternalInterceptAttribute(request => interceptor) { Order = order } }); } } if (!plan.Has <ProxyDirective>()) { plan.Add(new ProxyDirective()); } }
/// <summary> /// Adds a <see cref="ConstructorInjectionDirective"/> to the plan for the constructor /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { Ensure.ArgumentNotNull(plan, "plan"); var constructors = this.selector.SelectConstructorsForInjection(plan.Type); if (constructors == null) { return; } foreach (ConstructorInfo constructor in constructors) { var hasInjectAttribute = constructor.HasAttribute(this.settings.InjectAttribute); var hasObsoleteAttribute = constructor.HasAttribute(typeof(ObsoleteAttribute)); var directive = new ConstructorInjectionDirective(constructor, this.injectorFactory.Create(constructor)) { HasInjectAttribute = hasInjectAttribute, HasObsoleteAttribute = hasObsoleteAttribute, }; plan.Add(directive); } }
/// <summary> /// Adds a <see cref="PropertyInjectionDirective"/> to the plan for each property /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { foreach (PropertyInfo property in Selector.SelectPropertiesForInjection(plan.Type)) plan.Add(new PropertyInjectionDirective(property, InjectorFactory.Create(property))); }
/// <summary> /// Registers static interceptors defined by attributes on the class for all candidate /// methods on the class, execept those decorated with a <see cref="DoNotInterceptAttribute"/>. /// </summary> /// <param name="type">The type whose activation plan is being manipulated.</param> /// <param name="plan">The activation plan that is being manipulated.</param> /// <param name="candidates">The candidate methods to intercept.</param> protected virtual void RegisterClassInterceptors( Type type, IPlan plan, IEnumerable<MethodInfo> candidates ) { InterceptAttribute[] attributes = type.GetAllAttributes<InterceptAttribute>(); if ( attributes.Length == 0 ) { return; } foreach ( MethodInfo method in candidates ) { PropertyInfo property = method.GetPropertyFromMethod( type ); ICustomAttributeProvider provider = (ICustomAttributeProvider) property ?? method; if ( !provider.HasAttribute<DoNotInterceptAttribute>() ) { RegisterMethodInterceptors( type, method, attributes ); } } // Indicate that instances of the type should be proxied. if ( !plan.Has<ProxyDirective>() ) { plan.Add( new ProxyDirective() ); } }
/// <summary> /// Contributes to the specified plan. /// </summary> /// <param name="plan">The plan that is being generated.</param> public virtual void Execute( IPlan plan ) { IEnumerable<MethodInfo> candidates = GetCandidateMethods( plan.Type ); RegisterClassInterceptors( plan.Type, plan, candidates ); foreach ( MethodInfo method in candidates ) { PropertyInfo property = method.GetPropertyFromMethod( plan.Type ); ICustomAttributeProvider provider = (ICustomAttributeProvider) property ?? method; InterceptAttribute[] attributes = provider.GetAllAttributes<InterceptAttribute>(); if ( attributes.Length == 0 ) { continue; } RegisterMethodInterceptors( plan.Type, method, attributes ); // Indicate that instances of the type should be proxied. if ( !plan.Has<ProxyDirective>() ) { plan.Add( new ProxyDirective() ); } } }
/// <summary> /// Registers static interceptors defined by attributes on the class for all candidate /// methods on the class, execept those decorated with a <see cref="DoNotInterceptAttribute"/>. /// </summary> /// <param name="type">The type whose activation plan is being manipulated.</param> /// <param name="plan">The activation plan that is being manipulated.</param> /// <param name="candidates">The candidate methods to intercept.</param> protected override void RegisterClassInterceptors( Type type, IPlan plan, IEnumerable<MethodInfo> candidates ) { NotifyOfChangesAttribute[] attributes = type.GetAllAttributes<NotifyOfChangesAttribute>(); if ( attributes.Length == 0 ) { return; } foreach ( MethodInfo method in candidates ) { if ( !method.HasAttribute<DoNotNotifyOfChangesAttribute>() ) { RegisterMethodInterceptors(type, method, attributes); } } // Indicate that instances of the type should be proxied. if ( !plan.Has<ProxyDirective>() ) { plan.Add( new ProxyDirective() ); } }