protected virtual void CollectFromConfiguration(ComponentModel model) { if (model.Configuration == null) return; IConfiguration interceptors = model.Configuration.Children["interceptors"]; if (interceptors == null) return; foreach(IConfiguration interceptor in interceptors.Children) { String value = interceptor.Value; if (!ReferenceExpressionUtil.IsReference(value)) { String message = String.Format( "The value for the interceptor must be a reference " + "to a component (Currently {0})", value); throw new ConfigurationErrorsException(message); } InterceptorReference interceptorRef = new InterceptorReference( ReferenceExpressionUtil.ExtractComponentKey(value) ); model.Interceptors.Add(interceptorRef); model.Dependencies.Add( CreateDependencyModel(interceptorRef) ); } }
/// <inheritDoc/> public InterceptorReference[] SelectInterceptors(ComponentModel model, InterceptorReference[] refs) { // // Add interceptors that have been otherwise configured for this component (e.g., through an attribute // on the class) // List<InterceptorReference> interceptors = new List<InterceptorReference>(); interceptors.AddRange(model.Interceptors); // Add the interceptors that are configured for this selector int idx = -1; foreach (InterceptorDescriptor descriptor in descriptors) { // Don't add interceptors to classes on the ignore list idx++; string modelFullClassName = model.Implementation.Namespace + "." + model.Implementation.Name; if (descriptor.IgnoredTypes.Any(fullClassName => (modelFullClassName).Equals(fullClassName))) continue; // If the model's namespace matches any of the given namespace prefixes, then add the interceptor to it if (model.Implementation.Namespace == null) continue; if (descriptor.NamespacePrefixes.Any(prefix => model.Implementation.Namespace.StartsWith(prefix))) { // Locate interceptor by index using name set in InterceptorsInstaller interceptors.Add(InterceptorReference.ForKey(InterceptorNamePrefix + idx)); } } return interceptors.ToArray(); }
protected virtual void CollectFromConfiguration(ComponentModel model) { if (model.Configuration == null) return; var interceptors = model.Configuration.Children["interceptors"]; if (interceptors == null) return; foreach (var interceptor in interceptors.Children) { var value = interceptor.Value; if (!ReferenceExpressionUtil.IsReference(value)) { throw new Exception( String.Format("The value for the interceptor must be a reference to a component (Currently {0})", value)); } var reference = new InterceptorReference(ReferenceExpressionUtil.ExtractComponentKey(value)); model.Interceptors.Add(reference); model.Dependencies.Add(CreateDependencyModel(reference)); } var options = ProxyUtil.ObtainProxyOptions(model, true); CollectSelector(interceptors, options); CollectHook(interceptors, options); }
public InterceptorReference[] SelectInterceptors(ComponentModel model, InterceptorReference[] interceptors) { return new[] { new InterceptorReference(interceptorType), }; }
public bool Equals(InterceptorReference other) { if (other == null) { return(false); } return(Equals(referencedComponentName, other.referencedComponentName)); }
public bool Equals(InterceptorReference other) { if (other == null) { return(false); } return(Equals(lookupKey, other.lookupKey)); }
protected DependencyModel CreateDependencyModel(InterceptorReference interceptor) { if (string.IsNullOrEmpty(interceptor.ComponentKey)) { return new DependencyModel(DependencyType.Service, interceptor.ComponentKey, interceptor.ServiceType, false); } return new DependencyModel(DependencyType.ServiceOverride, interceptor.ComponentKey, interceptor.ServiceType, false); }
/// <summary> /// Select <see cref="LoggingAspect"/> as the interceptor. /// </summary> /// <param name="model">The model to select the interceptors for</param> /// <param name="interceptors">The interceptors selected by previous selectors in the pipeline or <see cref="P:Castle.Core.ComponentModel.Interceptors"/> if this is the first interceptor in the pipeline.</param> /// <returns> /// The interceptor for this model (in the current context) or a null reference /// </returns> public InterceptorReference[] SelectInterceptors(ComponentModel model, InterceptorReference[] interceptors) { var result = new List<InterceptorReference>(interceptors) { InterceptorReference.ForType<LoggingAspect>() }; return result.ToArray(); }
public InterceptorDescriptor(InterceptorReference[] interceptors, int insertIndex) : this(interceptors, Where.Insert) { if (insertIndex < 0) { throw new ArgumentOutOfRangeException("insertIndex", "insertIndex must be >= 0"); } this.insertIndex = insertIndex; }
/// <summary> /// Select the appropriate interceptor references. /// The interceptor references aren't necessarily registered in the model.Intereceptors /// </summary> /// <param name="model">The model to select the interceptors for</param><param name="interceptors"> /// The interceptors selected by previous selectors in the pipeline or /// <see cref="P:Castle.Core.ComponentModel.Interceptors"/> /// if this is the first interceptor in the pipeline.</param> /// <returns> /// The interceptor for this model (in the current context) or a null reference /// </returns> /// <remarks> /// If the selector is not interested in modifying the interceptors for this model, it /// should return <paramref name="interceptors"/> and the next selector in line would be executed. /// If the selector wants no interceptors to be used it can either return <c>null</c> or empty array. /// However next interceptor in line is free to override this choice. /// </remarks> public InterceptorReference[] SelectInterceptors(ComponentModel model, InterceptorReference[] interceptors) { // This clear is done becouse if not, when line 64 is execute we duplicate // the existing interceptor (One and Two). model.Interceptors.Clear(); // we are just adding one interceptor more. interceptors.ToList().ForEach(i => model.Interceptors.Add(i)); model.Interceptors.Add(InterceptorReference.ForType<InterceptorThree>()); return model.Interceptors.ToArray(); }
public void SelectInterceptors_AddsLoggingAspectToInterceptors() { // Arrange var interceptorSelector = new InterceptorSelector(); var interceptorReference = new InterceptorReference[0]; // Act var result = interceptorSelector.SelectInterceptors(null, interceptorReference); // Assert Assert.That(result.First().ToString(), Is.EqualTo(typeof(LoggingAspect).FullName)); }
public InterceptorReference[] SelectInterceptors(ComponentModel model, InterceptorReference[] interceptors) { if (model.Services.Any(s => s != typeof(IWatcher))) { return null; } if (Interceptors == InterceptorKind.None) { return null; } return new[] { new InterceptorReference(typeof(WasCalledInterceptor)), }; }
SelectInterceptors(ComponentModel model, InterceptorReference[] interceptors) { return new[] { InterceptorReference .ForType<DefaultValueInterceptor>(), InterceptorReference .ForType<ErrorHandlingInterceptor>(), InterceptorReference .ForType<CircuitBreakerInterceptor>() }; }
private void CollectInterceptors(ComponentModel model, IConfiguration interceptors) { foreach (var interceptor in interceptors.Children) { var value = interceptor.Value; if (!ReferenceExpressionUtil.IsReference(value)) { throw new Exception( String.Format("The value for the interceptor must be a reference to a component (Currently {0})", value)); } var reference = new InterceptorReference(ReferenceExpressionUtil.ExtractComponentKey(value)); model.Interceptors.Add(reference); } }
public bool Equals(InterceptorReference other) { if (other == null) { return(false); } if (!Equals(serviceType, other.serviceType)) { return(false); } if (!Equals(serviceOverrideComponent, other.serviceOverrideComponent)) { return(false); } return(true); }
protected IEnumerable<InterceptorReference> GetInterceptorsFor(ComponentModel model) { var interceptors = model.Interceptors.ToArray(); if (selectors != null) { foreach (var selector in selectors) { if (selector.HasInterceptors(model) == false) { continue; } interceptors = selector.SelectInterceptors(model, interceptors); if (interceptors == null) { interceptors = new InterceptorReference[0]; } } } return interceptors; }
public InterceptorDescriptor(InterceptorReference[] interceptors) { where = Where.Default; this.interceptors = interceptors; }
/// <summary> /// Adds the the specified interceptor as the first. /// </summary> /// <param name="interceptor">The interceptor.</param> public void AddFirst(InterceptorReference interceptor) { list.AddFirst(interceptor); }
public InterceptorDescriptor(InterceptorReference[] interceptors, Where where) { this.interceptors = interceptors; this.where = where; }
/// <summary> /// Select the appropriate interceptor references. /// The interceptor references aren't necessarily registered in the model.Intereceptors /// </summary> /// <param name="model">The model to select the interceptors for</param><param name="interceptors">The interceptors selected by previous selectors in the pipeline or <see cref="P:Castle.Core.ComponentModel.Interceptors"/> if this is the first interceptor in the pipeline.</param> /// <returns>The interceptor for this model (in the current context) or a null reference</returns> /// <remarks> /// If the selector is not interested in modifying the interceptors for this model, it /// should return <paramref name="interceptors"/> and the next selector in line would be executed. /// If the selector wants no interceptors to be used it can either return <c>null</c> or empty array. /// However next interceptor in line is free to override this choice. /// </remarks> public InterceptorReference[] SelectInterceptors(ComponentModel model, InterceptorReference[] interceptors) { return new[] { InterceptorReference.ForType<NancyRequestScopeInterceptor>() }; }
protected virtual void AddInterceptor(InterceptorReference interceptorRef, InterceptorReferenceCollection interceptors) { interceptors.Add(interceptorRef); }
/// <summary> /// Constructs the InterceptorAttribute pointing to /// a service /// </summary> /// <param name = "interceptorType"></param> public InterceptorAttribute(Type interceptorType) { interceptorRef = new InterceptorReference(interceptorType); }
/// <summary> /// Constructs the InterceptorAttribute pointing to /// a key to a interceptor /// </summary> /// <param name = "componentKey"></param> public InterceptorAttribute(string componentKey) { interceptorRef = new InterceptorReference(componentKey); }
protected DependencyModel CreateDependencyModel(InterceptorReference interceptor) { return new DependencyModel(DependencyType.Service, interceptor.ComponentKey, interceptor.ServiceType, false); }
/// <summary> /// Inserts the specified interceptor at the specified index. /// </summary> /// <param name="index">The index.</param> /// <param name="interceptor">The interceptor.</param> public void Insert(int index, InterceptorReference interceptor) { list.Insert(index, interceptor); }
public InterceptorReference[] SelectInterceptors(ComponentModel model, InterceptorReference[] interceptors) { return new[] { new InterceptorReference(typeof(WasCalledInterceptor)), }; }
/// <summary> /// Constructs the InterceptorAttribute pointing to /// a key to a interceptor /// </summary> /// <param name="componentKey"></param> public InterceptorAttribute(string componentKey) { interceptorRef = new InterceptorReference(componentKey); }
/// <summary> /// Constructs the InterceptorAttribute pointing to /// a service /// </summary> /// <param name="interceptorType"></param> public InterceptorAttribute(Type interceptorType) { interceptorRef = new InterceptorReference(interceptorType); }
private IHandler GetInterceptorHandler(InterceptorReference interceptorRef, IKernel kernel) { IHandler handler; if (interceptorRef.ReferenceType == InterceptorReferenceType.Interface) { handler = kernel.GetHandler(interceptorRef.ServiceType); } else { handler = kernel.GetHandler(interceptorRef.ComponentKey); } return handler; }