Example #1
0
 public EventComponent(Type eventType, Annotations annotations, WeldComponentManager manager) :
     base("", typeof(Events <>).MakeGenericType(eventType), annotations, manager)
 {
     _eventType   = eventType;
     _annotations = annotations;
     _lazyEventObserverMethods = new Lazy <EventObserverMethod[]>(ResolveObserverMethods);
 }
        public InterceptorMethodHandler(WeldComponentManager manager, MethodInfo method, Interceptor[] interceptors, ICreationalContext creationalContext)
        {
            _interceptorReferences = new LinkedList <IAroundInvokeInterceptor>(
                interceptors.Select(x => manager.GetReference(x, creationalContext))
                .Cast <IAroundInvokeInterceptor>());

            _bindingsLazy = new Lazy <IEnumerable <IInterceptorBinding> >(() => method.GetAnnotations().OfType <IInterceptorBinding>().ToArray());

            var returnType = method.ReturnType;

            if (returnType == typeof(Task))
            {
                _isAsync    = true;
                _taskCaster = TaskCasters.ForVoid();
            }
            else if (returnType.IsGenericType)
            {
                var genericType = returnType.GetGenericTypeDefinition();
                if (genericType == typeof(Task <>))
                {
                    _isAsync    = true;
                    _taskCaster = TaskCasters.ForType(returnType.GetGenericArguments()[0]);
                }
            }
        }
Example #3
0
        public Instance(WeldComponentManager manager, IQualifier[] qualifiers, IWeldComponent[] components, ICreationalContext creationalContext)
        {
            _qualifiers        = qualifiers;
            _components        = components;
            _creationalContext = creationalContext;

            _currentInjectionPoint = manager.GetService <CurrentInjectionPoint>();
            _injectionPoint        = _currentInjectionPoint.Peek();
        }
Example #4
0
 public ExtensionComponent(Type type, WeldComponentManager manager) : base(type.FullName, type, Weld.Annotations.Empty, manager)
 {
     try
     {
         _instance = (IExtension)Activator.CreateInstance(type);
     }
     catch (Exception e)
     {
         throw new CreationException(type, e);
     }
 }
Example #5
0
        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())));
            }
        }
Example #6
0
        private AbstractComponent(Type type, IAnnotations annotations, WeldComponentManager manager)
        {
            Annotations = annotations;
            var qualifierSet = new HashSet <IQualifier>(Annotations.OfType <IQualifier>());

            if (qualifierSet.All(x => (x is AnyAttribute)))
            {
                qualifierSet.Add(DefaultAttribute.Instance);
            }

            Type                   = type;
            Manager                = manager;
            Scope                  = annotations.OfType <ScopeAttribute>().Select(x => x.GetType()).FirstOrDefault() ?? typeof(DependentAttribute);
            IsProxyRequired        = typeof(NormalScopeAttribute).IsAssignableFrom(Scope) && !Annotations.OfType <UnwrapAttribute>().Any();
            _lazyBuildPlan         = new Lazy <BuildPlan>(GetBuildPlan);
            IsConditionalOnMissing = Annotations.OfType <ConditionalOnMissingComponentAttribute>().Any();
        }
Example #7
0
        private AbstractComponent(Type type, IEnumerable <IBinderAttribute> binders,
                                  Type scope, WeldComponentManager manager)
        {
            var qualifierSet = new HashSet <IQualifier>(binders.OfType <IQualifier>());

            if (qualifierSet.All(x => (x is AnyAttribute)))
            {
                qualifierSet.Add(DefaultAttribute.Instance);
            }

            Type                   = type;
            Manager                = manager;
            Binders                = binders;
            Qualifiers             = qualifierSet;
            Scope                  = scope;
            IsProxyRequired        = typeof(NormalScopeAttribute).IsAssignableFrom(scope);
            _lazyBuildPlan         = new Lazy <BuildPlan>(GetBuildPlan);
            IsConditionalOnMissing = binders.OfType <ConditionalOnMissingComponentAttribute>().Any();
        }
Example #8
0
        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);
            }
        }
Example #9
0
 public ProducerProperty(IWeldComponent component, PropertyInfo property, IAnnotations annotations, WeldComponentManager manager)
     : base(component, property, property.PropertyType, annotations, manager)
 {
     _property = property;
 }
Example #10
0
 public ProducerField(IWeldComponent component, IAnnotatedField field, WeldComponentManager manager)
     : this(component, field.Field, field.Annotations, manager)
 {
 }
Example #11
0
 private ProducerField(IWeldComponent component, FieldInfo field, IAnnotations annotations, WeldComponentManager manager)
     : base(component, field, field.FieldType, annotations, manager)
 {
     _field = field;
 }
Example #12
0
 private CormoApplication()
 {
     Environment = new WeldEnvironment();
     Manager     = new WeldComponentManager("deployment");
     Deployer    = new AttributeScanDeployer(Manager, Environment);
 }
Example #13
0
 public ValueComponent(object instance, IEnumerable <IQualifier> qualifiers, Type scope, WeldComponentManager manager)
     : base(instance.GetType().FullName, instance.GetType(), qualifiers, scope, manager)
 {
     _instance = instance;
 }
Example #14
0
        private ClassComponent(ClassComponent parent, Type type, IEnumerable <IBinderAttribute> binders, Type scope, WeldComponentManager manager, GenericUtils.Resolution typeResolution)
            : base(new ComponentIdentifier(parent.Id.Key, type), type, binders, scope, manager,
                   parent.PostConstructs.Select(x => GenericUtils.TranslateMethodGenericArguments(x, typeResolution.GenericParameterTranslations)).ToArray())
        {
            parent.TransferInjectionPointsTo(this, typeResolution);
            _lazyMixins = new Lazy <Mixin[]>(() => Manager.GetMixins(this));

            _lazyInterceptors = new Lazy <Interceptor[]>(() => new Interceptor[0]);
            //_lazyInterceptors = new Lazy<Interceptor[]>(() => Manager.GetInterceptors(this));
            //_interceptedMethods = InitInterceptedMethods();
        }
Example #15
0
 protected AbstractComponent(string idSuffix, Type type, IAnnotations annotations, WeldComponentManager manager)
     : this(type, annotations, manager)
 {
     _id = new ComponentIdentifier(string.Format("{0}-{1}-{2}", manager.Id, GetType().Name, idSuffix));
 }
Example #16
0
 public void Setup()
 {
     _manager  = new WeldComponentManager("test");
     _deployer = new AttributeScanDeployer(_manager, new WeldEnvironment());
 }
Example #17
0
 public ExceptionHandlerDispatcher(WeldComponentManager manager, IEnumerable <EventObserverMethod> handlers)
 {
     _handlerResolver = new ObserverResolver(manager, handlers.ToArray());
 }
Example #18
0
 public InstanceComponent(Type baseType, IAnnotations annotations, WeldComponentManager manager, IWeldComponent[] components)
     : base("", typeof(Instance <>).MakeGenericType(baseType), annotations, manager)
 {
     _baseType   = baseType;
     _components = components;
 }
Example #19
0
 public ValueComponent(object instance, WeldComponentManager manager)
     : base(instance.GetType().FullName, instance.GetType(), Weld.Annotations.Empty, manager)
 {
     _instance = instance;
 }
Example #20
0
 public ProducerProperty(IWeldComponent component, PropertyInfo property, IEnumerable <IBinderAttribute> binders, Type scope, WeldComponentManager manager)
     : base(component, property, property.PropertyType, binders, scope, manager)
 {
     _property = property;
 }
Example #21
0
 public MixinResolver(WeldComponentManager manager, IEnumerable <Mixin> allComponents) : base(manager, allComponents)
 {
 }
Example #22
0
        //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;
        }
Example #23
0
 public InterceptorResolver(WeldComponentManager manager, IEnumerable <Interceptor> allComponents)
     : base(manager, allComponents)
 {
 }
Example #24
0
 protected ContextualResolver(WeldComponentManager manager, IEnumerable <TComponent> allComponents) : base(manager, allComponents)
 {
 }
Example #25
0
 public void Initialize(WeldComponentManager componentManager)
 {
     _componentManager = componentManager;
 }
Example #26
0
 protected TypeSafeResolver(WeldComponentManager manager, IEnumerable <TComponent> allComponents)
 {
     Manager = manager;
     _registeredComponents = allComponents;
     _allComponents        = new ConcurrentBag <TComponent>(_registeredComponents);
 }
Example #27
0
 public ClassComponent(Type type, IEnumerable <IBinderAttribute> binders, Type scope, WeldComponentManager manager, MethodInfo[] postConstructs)
     : base(type, binders, scope, manager, postConstructs)
 {
     _lazyMixins       = new Lazy <Mixin[]>(() => Manager.GetMixins(this));
     _lazyInterceptors = new Lazy <Interceptor[]>(() => new Interceptor[0]);
 }
Example #28
0
 protected AbstractComponent(ComponentIdentifier id, Type type, IAnnotations annotations, WeldComponentManager manager)
     : this(type, annotations, manager)
 {
     _id = id;
 }
Example #29
0
 protected AbstractProducer(IWeldComponent declaringComponent, MemberInfo member, Type returnType, IAnnotations annotations, WeldComponentManager manager)
     : base(Formatters.Member(member), returnType, annotations, manager)
 {
     _containsGenericParameters = GenericUtils.MemberContainsGenericArguments(member);
     DeclaringComponent         = declaringComponent;
 }
Example #30
0
 public ProducerMethod(IWeldComponent declaringComponent, MethodInfo method, IEnumerable <IBinderAttribute> binders, Type scope, WeldComponentManager manager)
     : base(declaringComponent, method, method.ReturnType, binders, scope, manager)
 {
     _method = method;
 }