/// <summary>
        /// Adds the mapper to the list in the map, creating a new list if none exists
        /// </summary>
        /// <param name="map">The map.</param>
        /// <param name="key">The key.</param>
        /// <param name="mapper">The mapper.</param>
        private void AddToList(Dictionary<Type, List<EntityMapperBase>> map, Type key, EntityMapperBase mapper)
        {
            List<EntityMapperBase> list;
            if (map.TryGetValue(key, out list))
            {
                list.Add(mapper);
                return;
            }

            list = new List<EntityMapperBase>() {mapper};
            map.Add(key, list);
        }
        /// <summary>
        /// Builds the mapper. MapsWith attribute takes priority over InferMappingFor. Also, multiple mapping attributes are currently unsupported.
        /// </summary>
        /// <param name="descriptor">The descriptor.</param>
        protected virtual void BuildMapper(ControllerDescriptor descriptor)
        {
            var mapperAttribute = descriptor.ControllerType.GetCustomAttributes(typeof (MapsWithAttribute), false) as MapsWithAttribute[];
            if (mapperAttribute != null && mapperAttribute.Length == 1)
            {
                mapper = Activator.CreateInstance(mapperAttribute[0].MapperType) as EntityMapperBase;

                if (mapper != null)
                {
                    MapperRepository.Instance.RegisterMapper(mapper);
                    return;
                }
            }

            var inferredAttribute = descriptor.ControllerType.GetCustomAttributes(typeof(InferMappingForAttribute), false) as InferMappingForAttribute[];
            if (inferredAttribute != null && inferredAttribute.Length == 1)
            {
                var mapperType =
                    typeof (EntityMapper<,>).MakeGenericType(new Type[]
                                                                 {
                                                                     descriptor.ControllerType as Type,
                                                                     inferredAttribute[0].TargetType
                                                                 });
                mapper =
                    Activator.CreateInstance(mapperType) as EntityMapperBase;

                // configure the mapper based on the strict flag.
                if (inferredAttribute[0].Strict)
                    mapper.InferStrictOnly();
                else
                    mapper.InferOnly();

                MapperRepository.Instance.RegisterMapper(mapper);
            }
        }
 /// <summary>
 /// Registers the mapper.
 /// </summary>
 /// <param name="mapper">The mapper.</param>
 public void RegisterMapper(EntityMapperBase mapper)
 {
     AddToList(sourceMapping, mapper.Source, mapper);
     AddToList(targetMapping, mapper.Target, mapper);
 }