Ejemplo n.º 1
0
        public static ConstructorInjection InspectConstructor(IComponentInfo ctx, IKernel kernel, ConstructorInfo ctor)
        {
            var item = new ConstructorInjection(ctor.GetParameters().Select(p => AttributeProviderInspector.InspectParameter(ctx, kernel, p)).ToArray())
            {
                Member            = ctor,
                Creator           = ctor.GetCreator(),
                IsMarkedInjection = ctor.HasAttribute <InjectAttribute>(false),
            };

            return(item);
        }
Ejemplo n.º 2
0
        public void Inspect(IComponentInfo info, IKernel kernel, Type componentType, string injectionKey)
        {
            injectionInspector = new AttributeProviderInspector();
            ignoreVisitor      = AttributeProviderVisitorRepository.Get <bool>();

            Guard.NotNull(ignoreVisitor, "ignoreVisitor");

            if (!ignoreVisitor.VisitType(componentType))//if (!componentType.IsSystemAssemblyOfType())
            {
                InspectFields(info, kernel, componentType);
                InspectPropeties(info, kernel, componentType);
                InspectMethods(info, kernel, componentType);
            }

            info.ExtendedProperties[injectionKey]         = injectionInspector.Injections;
            info.ExtendedProperties["MembersRegistered"]  = injectionInspector.Exports;
            info.ExtendedProperties["AppSettings"]        = injectionInspector.AppSettingInjections;
            info.ExtendedProperties["subscribeProviders"] = injectionInspector.SubscribeInfoFactoryProviders;

            injectionInspector = null;
        }
Ejemplo n.º 3
0
        private static IMemberInjection CreateMethodInjection(IComponentInfo ctx, IKernel kernel, MethodInfo m, InjectAttribute att)
        {
            var ps = m.GetParameters();
            List <IDependency> dependencyList = new List <IDependency>(ps.Length);

            foreach (var p in ps)
            {
                if (p.ParameterType.IsByRef || p.IsRetval || p.IsOut)
                {
                    return(null);
                }
                dependencyList.Add(AttributeProviderInspector.InspectParameter(ctx, kernel, p));
            }

            var id        = att != null ? att.Id : string.Empty;
            var injection = new MethodInjection(dependencyList.ToArray())//方法注入元数据
            {
                Member      = m,
                Method      = DynamicMethodFactory.GetProc(m),
                Reinjection = att.Reinjection,
            };

            return(injection);
        }