Ejemplo n.º 1
0
        /// <summary>
        /// Gets the inject entity attribute.
        /// </summary>
        /// <param name="memberInfo">The member info.</param>
        /// <returns></returns>
        public static InjectEntityAttribute GetInjectEntityAttribute(MemberInfo memberInfo)
        {
            InjectEntityAttribute attribute = Attribute.GetCustomAttribute(memberInfo, typeof(InjectEntityAttribute), true) as InjectEntityAttribute;

            if (attribute != null)
            {
                attribute.Name = attribute.Name ?? memberInfo.Name;
            }
            return(attribute);
        }
        public object GetValueFor(object id, InjectEntityAttribute attribute, PropertyInfo property)
        {
            Type   repositoryType = typeof(IRepository <>).MakeGenericType(property.PropertyType);
            object repository     = kernel.Resolve(repositoryType);

            return(repositoryType
                   .GetMethod("FindOne", new Type[] { typeof(DetachedCriteria) })
                   .Invoke(repository, new object[]
            {
                DetachedCriteria
                .For(property.PropertyType)
                .Add(Expression.IdEq(id))
            }));
        }
        public object GetValueFor(object id, InjectEntityAttribute attribute, PropertyInfo property)
        {
            Type repositoryType = typeof(IRepository<>).MakeGenericType(property.PropertyType);
            object repository = kernel.Resolve(repositoryType);

            return repositoryType
                .GetMethod("FindOne", new Type[] { typeof(DetachedCriteria) })
                .Invoke(repository, new object[]
                    {
                        DetachedCriteria
                            .For(property.PropertyType)
                            .SetFetchMode(attribute.EagerLoad, FetchMode.Eager)
                            .Add(Expression.IdEq(id))
                    });
        }
Ejemplo n.º 4
0
 private static object ConvertKey(object instance, InjectEntityAttribute attribute)
 {
     if (Scope.Input[attribute.Name] == null)
     {
         return(null);
     }
     try
     {
         return(ConversionUtil.ConvertTo(attribute.IdType, Scope.Input[attribute.Name]));
     }
     catch (Exception e)
     {
         logger.Debug(string.Format("Failed to convert ID ({0}) for {1} to integer.", attribute.Name, instance), e);
         return(null);
     }
 }
        public object GetValueFor(object id, InjectEntityAttribute attribute, PropertyInfo property)
        {
            log.DebugFormat("Type of property for generic repository is {0}", property.PropertyType);

            Type repositoryType = typeof(IRepository <>).MakeGenericType(property.PropertyType);

            log.DebugFormat("repsitory service is {0}", repositoryType);

            object repository = kernel.Resolve(repositoryType);

            log.DebugFormat("repsitory is {0}", repository.GetType());

            return(repositoryType
                   .GetMethod("Get")
                   .Invoke(repository, new object[] { id }));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Usually the implementation will look in the configuration property
        /// of the model or the service interface, or the implementation looking for
        /// something.
        /// </summary>
        /// <param name="kernel">The kernel instance</param>
        /// <param name="model">The component model</param>
        public void ProcessModel(IKernel kernel, ComponentModel model)
        {
            PropertyInfo[] properties = model.Implementation.GetProperties(BINDING_FLAGS_SET);

            IDictionary <InjectAttribute, PropertyInfo>       inMembers       = new Dictionary <InjectAttribute, PropertyInfo>();
            IDictionary <InjectEntityAttribute, PropertyInfo> inEntityMembers = new Dictionary <InjectEntityAttribute, PropertyInfo>();

            for (int i = 0; i < properties.Length; i++)
            {
                InjectAttribute injectAttribute = AttributeUtil.GetInjectAttribute(properties[i]);
                if (injectAttribute != null)
                {
                    inMembers.Add(injectAttribute, properties[i]);
                }

                InjectEntityAttribute injectEntityAttribute = AttributeUtil.GetInjectEntityAttribute(properties[i]);
                if (injectEntityAttribute != null)
                {
                    inEntityMembers.Add(injectEntityAttribute, properties[i]);
                }
            }
            model.ExtendedProperties[InMembers]       = inMembers;
            model.ExtendedProperties[InEntityMembers] = inEntityMembers;
        }
 public bool IsSatisfiedBy(InjectEntityAttribute attribute, PropertyInfo property)
 {
     return !string.IsNullOrEmpty(attribute.EagerLoad);
 }
 public bool IsSatisfiedBy(InjectEntityAttribute attribute, PropertyInfo property)
 {
     return kernel.HasComponent(typeof(IRepository<>).MakeGenericType(property.PropertyType));
 }
        public object GetValueFor(object id, InjectEntityAttribute attribute, PropertyInfo property)
        {
            log.DebugFormat("Type of property for generic repository is {0}", property.PropertyType);

            Type repositoryType = typeof(IRepository<>).MakeGenericType(property.PropertyType);
            log.DebugFormat("repsitory service is {0}", repositoryType);

            object repository = kernel.Resolve(repositoryType);
            log.DebugFormat("repsitory is {0}", repository.GetType());

            return repositoryType
                .GetMethod("Get")
                .Invoke(repository, new object[] { id });
        }
Ejemplo n.º 10
0
 private static object ConvertKey(object instance, InjectEntityAttribute attribute)
 {
     if (Scope.Input[attribute.Name] == null) return null;
     try
     {
         return ConversionUtil.ConvertTo(attribute.IdType, Scope.Input[attribute.Name]);
     }
     catch (Exception e)
     {
         logger.Debug(string.Format("Failed to convert ID ({0}) for {1} to integer.", attribute.Name, instance), e);
         return null;
     }
 }
 public bool IsSatisfiedBy(InjectEntityAttribute attribute, PropertyInfo property)
 {
     return(kernel.HasComponent(typeof(IRepository <>).MakeGenericType(property.PropertyType)));
 }
 public bool IsSatisfiedBy(InjectEntityAttribute attribute, PropertyInfo property)
 {
     return(!string.IsNullOrEmpty(attribute.EagerLoad));
 }