       @::register= (aClass, aOptions)-> @constructor.register aClass, aOptions
       @::unregister= (aName)-> @constructor.unregister aName
       @::registered= (aName)-> Factory(aName)
-      @::registeredClass= (aName)-> @constructor[aName]
+      @::registeredClass= (aName)->
+        aName = Factory.formatName aName
+        @constructor[aName]
 
     inherits Factory, CustomFactory
 

isObject              = (v)-> v? and 'object' is typeof v

module.exports = (Factory, aOptions)->
  flatOnly = aOptions.flatOnly if isObject aOptions

  extend Factory,
    _objects: registeredObjects = {}
    _aliases: aliases = {}
    getNameFromClass: (aClass)->
      result = aClass.name
      len = result.length
      vFactoryName = Factory.name
      throw new InvalidArgumentError('can not getNameFromClass: the '+vFactoryName+'(constructor) has no name error.') unless len
      result = result.substring(0, len-vFactoryName.length) if vFactoryName and vFactoryName.length and result.substring(len-vFactoryName.length) is vFactoryName
      result
    getRealNameFromAlias: (alias)->
      aliases[alias]
    alias: alias = (aClass, aAliases...)->
      # aClass could be a class or class name.
      aClass = Factory.getNameFromClass(aClass) if isFunction aClass
      #vLowerName = vName.toLowerCase()
      #if registeredObjects.hasOwnProperty(aClass)
      for alias in aAliases
        aliases[alias] = aClass
      return

        _register: _register
        unregister: (aName)->
          if isString aName
            aName = Factory.formatName aName
            vClass = Factory[aName]
          else
            vClass = aName
