public Interceptor(IAnnotatedType type, WeldComponentManager manager, bool allowPartialInterception) : base(type, manager) { AllowPartialInterception = allowPartialInterception; InterceptorBindings = Annotations.OfType <IInterceptorBinding>().Select(x => x.GetType()).ToArray(); InterceptorTypes = AllInterceptorTypes.Where(x => x.IsAssignableFrom(type.Type)).ToArray(); if (!InterceptorBindings.Any()) { throw new InvalidComponentException(type.Type, "Interceptor must have at least one interceptor-binding attribute"); } if (!InterceptorTypes.Any()) { throw new InvalidComponentException(type.Type, "Interceptor must implement " + string.Join(" or ", AllInterceptorTypes.Select(x => x.ToString()))); } }
private static IEnumerable <EventObserverMethod> FindEventObservers(IAnnotatedType type, IWeldComponent component) { foreach (var method in type.Methods) { var injectParams = method.Parameters .Where(p => p.Annotations.Any <ObservesAttribute>()) .ToArray(); if (!injectParams.Any()) { continue; } if (injectParams.Length > 1) { throw new InvalidComponentException(Formatters.MultipleObservesParameter(method.Method)); } var param = injectParams.Single(); yield return(new EventObserverMethod(component, param.Parameter, param.Annotations)); } }
public IWeldComponent MakeComponent(IAnnotatedType type) { if (typeof(IExtension).IsAssignableFrom(type.Type)) { return(new ExtensionComponent(type.Type, _manager)); } ManagedComponent component; var annotationAttribute = type.Annotations.OfType <InterceptorAttribute>().ToArray(); if (annotationAttribute.Any()) { component = new Interceptor(type, _manager, annotationAttribute.Any(x => x.AllowPartialInterception)); } else { component = type.Annotations.OfType <MixinAttribute>().Any()? (ManagedComponent) new Mixin(type, _manager): new ClassComponent(type, _manager); } return(component); }
protected ManagedComponent(IAnnotatedType type, WeldComponentManager manager) : base(type.Type.FullName, type.Type, type.Annotations, manager) { _isConcrete = !Type.ContainsGenericParameters; if (_isConcrete) { var methods = type.Methods.ToArray(); var iMethods = methods.Where(InjectionValidator.ScanPredicate).ToArray(); var iProperties = type.Properties.Where(InjectionValidator.ScanPredicate).ToArray(); var iCtors = type.Constructors.Where(InjectionValidator.ScanPredicate).ToArray(); var iFields = type.Fields.Where(InjectionValidator.ScanPredicate).ToArray(); var postConstructs = methods.Where(x => x.Annotations.OfType <PostConstructAttribute>().Any()).Select(x => x.Method).ToArray(); if (iCtors.Length > 1) { throw new InvalidComponentException(type.Type, "Multiple [Inject] constructors"); } var iCtor = iCtors.FirstOrDefault() ?? type.Constructors.First(x => !x.Parameters.Any()); _injectableConstructor = new InjectableConstructor(this, iCtor.Constructor); var methodInjects = iMethods.Select(m => new InjectableMethod(this, m.Method, null)).ToArray(); var fieldInjects = iFields.Select(f => new FieldInjectionPoint(this, f)).ToArray(); var propertyInjects = iProperties.Select(p => new PropertyInjectionPoint(this, p)).ToArray(); AddMemberInjectionPoints(fieldInjects.Cast <IWeldInjetionPoint>().Union(propertyInjects).ToArray()); AddInjectableMethods(methodInjects); PostConstructs = postConstructs; ValidateMethodSignatures(); IsDisposable = typeof(IDisposable).IsAssignableFrom(Type); } }
//private ClassComponent(ClassComponent parent, ConstructorInfo ctor, IAnnotations Annotations, Type scope, WeldComponentManager manager, GenericResolver.Resolution typeResolution) // : base(new ComponentIdentifier(parent.Id.Key, ctor.DeclaringType), ctor, Annotations, scope, manager, // parent.PostConstructs.Select(x => GenericUtils.TranslateMethodGenericArguments(x, typeResolution.GenericParameterTranslations)).ToArray()) //{ // parent.TransferInjectionPointsTo(this, typeResolution); //} public ClassComponent(IAnnotatedType type, WeldComponentManager manager) : base(type, manager) { AnnotatedType = type; }
public ProcessAnnotatedType(IAnnotatedType annotatedType) { AnnotatedType = annotatedType; }
public void SetAnnotations(IAnnotations annotations) { AnnotatedType = new AnnotatedType(AnnotatedType.Type, annotations); }
public Mixin(IAnnotatedType type, WeldComponentManager manager) : base(type, manager) { MixinBindings = Annotations.OfType <IMixinBinding>().Select(x => x.GetType()); InterfaceTypes = Annotations.OfType <MixinAttribute>().SelectMany(x => x.InterfaceTypes).ToArray(); }