Exemplo n.º 1
0
        private object GetServiceScanField(Type serviceType, object serviceObj)
        {
            if (serviceType.IsInterface)
            {
                return(serviceObj);
            }
            //if dynamic proxy object,jump scan
            if (serviceObj.GetType().Name.EndsWith("Proxy"))
            {
                return(serviceObj);
            }

            //check for circular references.
            if (ScanedType.Contains(serviceType))
            {
                throw new InvalidOperationException("Existence of circular references or repeat create instance operate.");
            }
            else
            {
                ScanedType.Add(serviceType);
            }

            //scan field
            var fieldInfos = serviceType.GetRuntimeFields();

            foreach (var field in fieldInfos)
            {
                if (ServiceAttribute.Exist(field))
                {
                    if (SpringContext.ServiceCollection.ContainsKey(field.FieldType))
                    {
                        field.SetValue(serviceObj, GetService(field.FieldType));
                    }
                }
            }
            return(serviceObj);
        }